0
votes

I am trying to program a function that deletes the message with the command sent by the user.

E.g.:

  • User sends command /delmes
  • Bot sends a response to the command
  • Bot deletes the message sent by the user

Everything I was able to find until now (that would help me) was this Stack Overflow Thread: discord.py delete author message after executing command

But when I used the code, as described in the solutions, I only received AttributeError: 'Bot' object has no attribute 'delete_message'.

The discord.py API Reference (https://discordpy.readthedocs.io/en/latest/migrating.html#models-are-stateful / https://discordpy.readthedocs.io/en/latest/api.html?highlight=delete%20message#message) only revealed that some of the code had changed with newer versions. So to speak client.delete_message would change to Message.delete(), if I interpreted it correctly!

After changing the code to what I thought it must be I received: NameError: name 'Message' is not defined

This is my code at the very last moment. (I am relatively new to discord.py and only used Python in school)

import discord
from discord.ext import commands
import random
import json

client = commands.Bot(command_prefix = '/', case_insensitive=True)

@client.command(pass_context=True)
async def delcommes(ctx):
    await ctx.send("This is the response to the users command!")
    await Message.delete(ctx.message, delay=3)
1

1 Answers

0
votes

I couldn't understand your question very good but as far as I understand, when command executed, then after bot sends message, you want to delete the command message, in that case it's /delmes. You can use await ctx.message.delete().

@client.command(pass_context=True)
async def delcommes(ctx):
    await ctx.send("This is the response to the users command!")
    await ctx.message.delete()