問題描述
我正在嘗試在我的機器人中使用意圖,但在運行以下代碼時:
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,你可以在導(dǎo)入后打印 discord.__version__
仔細(xì)檢查.最佳做法是對包使用 Python venv像這樣.此外,為了確保您始終訪問正確的 pip,您可以使用 python -m pip
.這意味著您始終將 pip 用于稍后將調(diào)用腳本的同一版本.
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.
這篇關(guān)于Discord.py:NameError:未定義名稱“意圖"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!