Discord bot在我运行命令时显示错误,但有时它仍然会运行命令



我做了两个简单的命令(ping(来告诉机器人的ping和(clear(来清除最后6条消息。当我运行ping命令时,它工作得很好,但它在控制台中提供了回溯。而clear命令根本不起作用,并且给出了下面的回溯

C:UserswelcomeDesktopPythonDiscord>bot1.py
Bot online
Ignoring exception in command clear:
Traceback (most recent call last):
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscorditerators.py", line 263, in next
return self.messages.get_nowait()
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libasyncioqueues.py", line 182, in get_nowait
raise QueueEmpty
asyncio.queues.QueueEmpty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordchannel.py", line 379, in purge
msg = await iterator.next()
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscorditerators.py", line 265, in next
raise NoMoreItems()
discord.errors.NoMoreItems
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:UserswelcomeDesktopPythonDiscordbot1.py", line 19, in clear
await ctx.channel.purge(limit=amount)
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordchannel.py", line 385, in purge
await strategy(to_delete)
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordchannel.py", line 303, in delete_messages
await self._state.http.delete_messages(self.id, message_ids)
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordhttp.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandsbot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:UserswelcomeAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

我的代码是

import discord
from discord.ext import commands
client=commands.Bot(command_prefix='!')
@client.event
async def on_ready():
print("Bot online")
@client.command(aliases = ['ping','latency'])
async def _ping(ctx):
await ctx.send(f'Chucky ping {round(client.latency*1000)}ms')
#@client.command(aliases = [''])
#async def _
@client.command()
async def clear(ctx, amount=6):
await ctx.channel.purge(limit=amount)
client.run('my token')

也许机器人程序缺少删除消息的前提。再次将机器人程序添加到服务器,并为其提供管理员权限。如果您将[client_id]更改为机器人的客户端id,则可以通过此链接进行操作。https://discord.com/oauth2/authorize?client_id=[clien_id]&scope=bot&权限=8如果你的机器人仍然没有做你想做的事的前提,也许可以试着给它一些排名。

最新更新