Discord.py: NameError: name #39;intents#39; is not defined(Discord.py:NameError:未定义名称“意图)
问题描述
我正在尝试在我的机器人中使用意图,但在运行以下代码时:
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:未定义名称“意图"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord.py:NameError:未定义名称“意图"
基础教程推荐
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
