Ad
How To Make Discord Bot Delete Messages Send By The Bot
I have made a discord bot that adds people to queue by a command and then shows the queue. I dont want the channel to fill up with unfinished queues. So I want the bot to delete its own messages.
Example:
user says: !dips
Bot says: 1. User #this is message 1.
Another user says: !dips
Bot says: 1. User, 2. Another user. #this is message 2.
Bot deletes now message 1. which is not needed anymore since the same information is in message 2.
Here is the python code I am working with.
@client.event
async def on_message(message):
if message.content.lower() in list_of_commands:
await message.channel.send(queue(arg1,arg2,arg3))
#After sending new message here, it should delete the old message.
Ad
Answer
You could declare the message as a variable and then delete it later.
@client.event
async def on_message(message):
if message.content.lower() in list_of_commands:
msg = await message.channel.send(queue(arg1,arg2,arg3))
# do your stuff
await msg.delete()
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad