Discord.py:名称错误:未定义名称"意图"



我正在尝试在我的机器人中使用意图,但在运行以下代码时:

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,我不知道为什么会发生这种情况。任何帮助都将被分配(:

您很可能实际上没有使用 1.5.1 discord.py,您可以在导入后打印discord.__version__进行仔细检查。最佳做法是将 Python venv 用于这样的包。 此外,为了确保您始终访问正确的点,您可以使用python -m pip.这意味着您始终将 pip 用于稍后调用脚本的相同版本。

执行此操作bot = commands.Bot(command_prefix=prefix, intent=discord.Intents.default() )而不是bot = commands.Bot(command_prefix=prefix, intent=intents)

最新更新