I am having trouble deleting discord bot's message. Here is the code to replicate the problem I am having:
import discord
from tools.config import TOKEN
bot = discord.Bot()
@bot.event
async def on_ready():
print(f"{bot.user} is ready and online!")
@bot.slash_command(name="chat", description="Тут можно добавить описание")
async def chat(ctx, msg):
bot_msg = await ctx.respond(f'some message with tagging {ctx.author.mention}')
await bot_msg.delete(delay=5)
bot.run(TOKEN)
And I get the error:
await bot_msg.delete(delay=5)
AttributeError: 'Interaction' object has no attribute 'delete'
I am using py-cord==2.4.1 but I believe it's the same thing as discord.py
Pycordis not the same asdiscord.py.Pycordis a fork ofdiscord.py.Slash commands on discord.py
There are two ways of doing this, either by using Client from
discordor Bot fromdiscord.ext.commands.discord.Client method:
Meanwhile, commands.Bot has the property
treewhich is basically the same as app_commands.CommandTree. The main advantage of commands.Bot, is the use of cogs.Here is how you initialise bot.
discord.pyhas resumed development ondiscord.pyafter halting it over a year ago. After the announcement of its hold, forks likePycordstarted popping up. For the question on which to use, it is up to you. But personally, I recommend sticking with the maindiscord.pylibrary.For more information on slash commands in
discord.py, discord.Interaction, discord.InteractionResponse.Deleting the bot's message
After replying to the command user with discord.InteractionResponse (which does not return a message object) you can delete with either the
delete_afterattribute, or by getting the original_response object and then deleting it.Or