client = discord.Client() TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents' 我该如何解决这个问题? python 新手

问题描述 投票:0回答:1

嘿,我是 python 的新手,我正在尝试创建一个多功能的 discord 机器人,我的机器人叫做 flea。不管怎样,我遇到了这个错误,但我不知道如何修复它,我通常能比较快地理解错误,但我似乎无法弄清楚。 This is what my code looks like。该代码旨在通过运行“on_ready”函数使我的机器人在不和谐(运行)时从离线状态转到在线状态

下图是我尝试修复问题后我的代码的样子,更改除了删除错误什么也没做,机器人仍然不会出现在不和谐的在线:screenshot 1screenshot 2

下面是我的 bot.py 文件中的当前代码,有同样的错误

> # imports import discord  # importing discord import responses  # importing responses.py file
> 
> 
> async def send_message(message, user_message, is_private):
>     try:
>         response = responses.response_handle(user_message)
>         await message.author.send(response) if is_private else await message.channel.send(response)
>     except Exception as e:
>         print(e)
> 
> 
> def run_flea():
>     token = 'my token'
>     client = discord.Client()  # here is the error
> 
>     @client.event
>     async def on_ready():  # this is when the bot gets started, it will call the "on_ready" function
>         print(f'{client.user} is now running')  # this tells us that our bot is up and ready
> 
>         client.run(token)
discord bots
1个回答
1
投票

这是因为您需要将意图声明为客户端变量的参数,只需插入此参数即可:

client = discord.Client(intents=discord.Intents.default())
© www.soinside.com 2019 - 2024. All rights reserved.