NameError: 'discord' is not defined?

别说谁变了你拦得住时间么 提交于 2021-02-05 07:12:05

问题


This is for a discord bot I am making, and I have tried to set the bot's status. I've found an answer that looks like await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for e/info")) and I have put it in an on_ready event function. However, it gives me the following exception:

Ignoring exception in on_ready
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", 
    line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\user\OneDrive\Desktop\EffeKtive\bot.py", line 14, in on_ready
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for 
      e/info"))
NameError: name 'discord' is not defined

I feel that I am missing an import.


回答1:


You'll need to import discord at the top of your code.




回答2:


You may have installed discord.py in a seperate location, try installing it to C:\Windows\system32>. You also may be missing an import. If you are trying to add commands, you also have to: from discord.ext import commands. Is it possible for you to post your code?



来源:https://stackoverflow.com/questions/61777446/nameerror-discord-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!