Ale*_*pic 30 python discord.py
我试图制作一个快速的不和谐机器人,我使用了以下代码:
\nimport discord\nfrom discord.ui import button, view\nfrom discord.ext import commands\n\nclient = discord.Client()\n\n@client.event\nasync def on_ready():\n print(\'Autenticazione riuscita. {0.user} \xc3\xa8 online!\'.format(client))\nRun Code Online (Sandbox Code Playgroud)\n但弹出这个错误:
\nimport discord\nfrom discord.ui import button, view\nfrom discord.ext import commands\n\nclient = discord.Client()\n\n@client.event\nasync def on_ready():\n print(\'Autenticazione riuscita. {0.user} \xc3\xa8 online!\'.format(client))\nRun Code Online (Sandbox Code Playgroud)\n我尝试通过在括号之间添加一些内容来提供一个论点,如下所示:
\nimport discord\nfrom discord.ui import button, view\nfrom discord.ext import commands\n\nclient = discord.Client(0)\n\n@client.event\nasync def on_ready():\n print(\'Autenticazione riuscita. {0.user} \xc3\xa8 online!\'.format(client))\nRun Code Online (Sandbox Code Playgroud)\n但我得到了这个错误:
\nClient.__init__() missing 1 required keyword-only argument: \'intents\'\nRun Code Online (Sandbox Code Playgroud)\n在另一台 PC 上,完全相同的代码、完全相同的模块和相同的 Python 版本运行得很好。我缺少什么?
\nCor*_*mer 49
Intents除非您需要指定特定值,否则您可以使用默认值。
client = discord.Client(intents=discord.Intents.default())
Run Code Online (Sandbox Code Playgroud)
正如第一条错误消息所示,它是一个仅关键字参数,因此您不能在discord.Client(discord.Intents.default())没有intents=.
有关更多详细信息,请参阅意图。
小智 7
使用旧版本,您无法收到消息。
尝试使用这个
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
Run Code Online (Sandbox Code Playgroud)