嘿,我是 python 的新手,我正在尝试创建一个多功能的 discord 机器人,我的机器人叫做 flea。不管怎样,我遇到了这个错误,但我不知道如何修复它,我通常能比较快地理解错误,但我似乎无法弄清楚。 。该代码旨在通过运行“on_ready”函数使我的机器人在不和谐(运行)时从离线状态转到在线状态
下图是我尝试修复问题后我的代码的样子,更改除了删除错误什么也没做,机器人仍然不会出现在不和谐的在线:,
下面是我的 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)
这是因为您需要将意图声明为客户端变量的参数,只需插入此参数即可:
client = discord.Client(intents=discord.Intents.default())