【问题标题】:module 'discord' has no attribute 'Intents' error模块“不和谐”没有属性“意图”错误
【发布时间】:2021-06-29 19:24:43
【问题描述】:

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

Traceback(最近一次调用最后一次): 文件“c:/Users/phara/Documents/GitHub/RayzeBot/bot.py”,第 41 行,在 意图 = discord.Intents.default() AttributeError:模块“discord”没有属性“Intents”

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()

我安装了最新版本的 discord API 并且正在运行 python 3.8 导致错误的原因是什么,我该如何解决?

【问题讨论】:

标签: python discord.py


【解决方案1】:

我刚刚运行了您的代码,它可以在我的电脑上运行。我正在使用 Python 3.6,但我认为这不应该是一个问题。也许尝试重新安装 discord API?

【讨论】:

  • 我试过了,但它给了我同样的问题。我会在早上尝试重新启动我的电脑,这可能会有所帮助。
  • 重新启动您的 PC 将无济于事。你只需要升级 discord.py
【解决方案2】:

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

【讨论】:

  • 感谢升级帮助,但 vscode 继续使用 1.3.2 虽然我已经安装了 1.6.0(我在 cmd 中签入)。他们有办法解决这个问题吗?
  • 刚刚解决了这个问题,必须使用 python 3.9 版本而不是 3.8。
  • 使用this在vscode中更改python版本
【解决方案3】:

这里有两种情况。

  1. 最明显的问题是不和谐不包含“意图”它包含“意图”。因此,您需要做的就是将 i 更改为大写 I。
  2. 第二个可能的问题可能是 Intent 版本的旧版本。 要确认您的版本,请按照新文件中提到的其他答案执行并运行该文件。

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 2017-11-12
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 2015-08-13
    相关资源
    最近更新 更多