Discord.py: NameError: name 'intents' is not defined

Discord.py: NameError: name 'intents' is not defined

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

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'

我是运行Python3.8.2,不知道为什么会这样。任何帮助将不胜感激(:

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