Discord.py:NameError:未定义名称"intents" [英] Discord.py: NameError: name 'intents' is not defined
问题描述
我试图在我的机器人中使用意图,但是在运行以下代码时:
I'm trying to use intents in my bot but when running the following code:
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=prefix, intent=intents)
我得到了错误:
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discor
Traceback (most recent call last):
File "main.py", line 3, in <module>
intents = discord.Intents.default()
AttributeError: module 'discord' has no attribute 'Intents'
我正在运行Python 3.8.2,但我不知道为什么会这样.任何帮助都会被贬低(:
I am running Python 3.8.2, and I don't know why this is happening. Any help would be appriceated (:
推荐答案
您很可能实际上并未使用discord.py 1.5.1,可以在导入 discord .__ version __
后再打印以进行仔细检查..最佳做法是对包使用Python venv 像这样.另外,要确保您始终访问正确的pip,可以使用 python -m pip
.这意味着您始终将pip用于与以后调用脚本相同的版本.
You are most likely not actually using discord.py 1.5.1, you can print discord.__version__
after importing it to double check. Best practise is to use Python venv for packages like this.
Additionally, to make sure you are always accessing the correct pip, you can use python -m pip
. This means you are always using pip for the same version you will invoke the script with later.
这篇关于Discord.py:NameError:未定义名称"intents"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!