问题
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