首页 > 解决方案 > 模块“不和谐”没有属性“意图”错误

问题描述

我正在尝试编写一个不和谐的机器人,但是当我运行程序时它给出了错误

回溯(最近一次通话):文件“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 导致错误的原因是什么,我该如何解决?

标签: pythondiscord.py

解决方案


似乎是一个不和谐的版本问题。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

推荐阅读