Client.__init__()“缺少 1 个必需的仅关键字参数:‘intents’”,或“需要 1 个位置参数,但给出了 2 个”
- 2025-01-14 08:50:00
- admin 原创
- 99
问题描述:
我试图为 discord 制作一个快速机器人,并使用了以下代码:
import discord
from discord.ui import button, view
from discord.ext import commands
client = discord.Client()
@client.event
async def on_ready():
print('Autenticazione riuscita. {0.user} è online!'.format(client))
但是弹出这个错误:
Client.__init__() missing 1 required keyword-only argument: 'intents'
我尝试通过在括号之间放置一些内容来提供一个参数,如下所示:
import discord
from discord.ui import button, view
from discord.ext import commands
client = discord.Client(0)
@client.event
async def on_ready():
print('Autenticazione riuscita. {0.user} è online!'.format(client))
但是我却收到这个错误:
Client.__init__() takes 1 positional argument but 2 were given
在另一台电脑上,使用完全相同的代码、完全相同的模块和相同的 Python 版本就可以正常工作。我遗漏了什么?
解决方案 1:
您可以使用默认值,Intents
除非您需要指定特定的值。
client = discord.Client(intents=discord.Intents.default())
正如第一个错误消息所说,它是一个仅关键字参数,因此不能discord.Client(discord.Intents.default())
在没有的情况下编写intents=
。
请参阅意图以了解更多详细信息。
解决方案 2:
使用旧版本时,您无法获取消息。
尝试使用这个
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
解决方案 3:
我的建议是卸载您当前拥有的 discord.py 版本并安装版本 1.7.3。
我遇到了同样的问题,并意识到最近发布了该模块的新版本。一旦我恢复到旧版本,只需使用
client = discord.Client()
解决方案 4:
我遇到了同样的问题,这是一个版本问题使用:pip install -U discord==1.7.3 pip install -U discord.py==1.7.3
这应该可以解决这个问题,至少对我来说是这样
相关推荐
热门文章
项目管理软件有哪些?
热门标签
云禅道AD