REX
REX

Reputation: 33

discord.py bot finds channel messages to delete, but is showing its client id is the same as mine

I am trying to make a command called '!clear' that just removes the bots messages in a specific channel. This seems pretty straight forward using:

Client = discord.Client()
client = commands.Bot(command_prefix = "!")

@client.event
async def on_message(message):    
    if message.content.lower().startswith("!clear"):
        async for x in client.logs_from(message.channel, limit = 100):
            if str(message.author.id) == 'insert bots client id':
                await client.delete_message(x)
client.run(token)

However, i found it wasn't deleting any messages. So before checking message.author.id i added a simple print(message.author.id) to see what ids it is picking up. It appears that it is spitting out only my client id and not seeing its own messages. The weird thing though is that if i change the author.id check to my client id then it will delete my messages and also the bots messages. So for some reason the bot thinks that its client id is the same as mine so when it is in a server that isn't my test server, it doesn't have the right permissions to delete my messages so it fails, even though I only want it to delete its own messages.

Any help would be great.

Upvotes: 3

Views: 972

Answers (1)

Wright
Wright

Reputation: 3424

Don't you mean

if x.author.id == "bot id here":
    await client.delete_message(x)

After all, each message is being put in x each iteration. Using message refers to the message in the async def on_message(message) function. Which would be the person who used the command. aka, you.

Upvotes: 2

Related Questions