python - 模块“不和谐”没有属性“意图”错误
问题描述
我正在尝试编写一个不和谐的机器人,但是当我运行程序时它给出了错误
回溯(最近一次通话):文件“c:/Users/phara/Documents/GitHub/RayzeBot/bot.py”,第 41 行,intents = discord.Intents.default() AttributeError: module 'discord' has no attribute '意图'
import discord, asyncio, os, platform, sys
from discord.ext.commands import Bot
from discord.ext import commands
import time
import random
if not os.path.isfile("config.py"):
sys.exit("'config.py' not found! Please add it and try again.")
else:
import config
"""
Setup bot intents (events restrictions)
For more information about intents, please go to the following websites:
https://discordpy.readthedocs.io/en/latest/intents.html
https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents
Default Intents:
intents.messages = True
intents.reactions = True
intents.guilds = True
intents.emojis = True
intents.bans = True
intents.guild_typing = False
intents.typing = False
intents.dm_messages = False
intents.dm_reactions = False
intents.dm_typing = False
intents.guild_messages = True
intents.guild_reactions = True
intents.integrations = True
intents.invites = True
intents.voice_states = False
intents.webhooks = False
Privileged Intents (Needs to be enabled on dev page):
intents.presences = True
intents.members = True
"""
intents = discord.Intents.default()
我安装了最新版本的不和谐 API 并且正在运行 python 3.8 导致错误的原因是什么,我该如何解决?
解决方案
似乎是一个不和谐的版本问题。Intents被引入discord.py 1.5.0
import discord
print(discord.__version__)
这在您的电脑中应该小于 1.5。
更新不和谐
pip install --upgrade discord.py
或者,如果您想安装特定版本
pip install discord.py==1.5.0
推荐阅读
- video-streaming - 在 HLS 中提供相同音频再现的多种编码
- docker - 无法连接到 Kubernetes 的 ETCD
- arrays - 生成相邻元素不是 x+1 的二维数组
- arrays - 在 for 循环中选择数组的特定行
- ios - 如何将 AppClip 添加到 Siri 的附近建议?
- sql - 如何使用每个客户的最新状态更新提取数据
- swiftui - SwiftUI LazyGrid 动态列宽
- javascript - Javascript 暂停计时器按钮
- c++ - 我可以指示 g++ 编译扩展名不同于“.cpp”等的 c++ 源文件吗?
- flutter - 如何在 Flutter 中使用带有打印机名称的以太网 POS 打印机打印收据?