Josh-Addy
Josh-Addy

Reputation: 3

Discord bot shows error when i run commands but still it sometimes run the command

I made 2 simple commands (ping) to tell the ping of the bot and (clear) to clear last 6 messages. when i run the ping command it works fine but it gives traceback in the console. whereas the clear command isnt working at all and is giving the below traceback

C:\Users\welcome\Desktop\Python\Discord>bot1.py
Bot online
Ignoring exception in command clear:
Traceback (most recent call last):
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\iterators.py", line 263, in next
    return self.messages.get_nowait()
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\asyncio\queues.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:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\channel.py", line 379, in purge
    msg = await iterator.next()
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\iterators.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:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\welcome\Desktop\Python\Discord\bot1.py", line 19, in clear
    await ctx.channel.purge(limit=amount)
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\channel.py", line 385, in purge
    await strategy(to_delete)
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\channel.py", line 303, in delete_messages
    await self._state.http.delete_messages(self.id, message_ids)
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\http.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:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\welcome\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.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

and my code is

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')

Upvotes: 0

Views: 847

Answers (1)

Bence
Bence

Reputation: 26

Maybe the bot is missing the premission to delete messages. Add the bot to the server again, and give it administrator premissions. You can do it through this link, if you change the [client_id] to your bot's client id. https://discord.com/oauth2/authorize?client_id=[clien_id]&scope=bot&permissions=8 And if your bot still don't have the premission to do what you want, maybe try to give it some kind of rank.

Upvotes: 1

Related Questions