Learn to Code via Tutorials on Repl.it!

← Back to all posts
How to code a discord snipe command -_-
h
efgabc

How to code a discord snipe command using Python -_-

Voters
BumberDaDoge
efgabc
Comments
hotnewtop
RajatMenon1

snipe_message_author = {}
snipe_message_content = {}

@bot.event
async def on_message_delete(message):
snipe_message_author[message.channel.id] = message.author
snipe_message_content[message.channel.id] = message.content
await sleep(60)
del snipe_message_author[message.channel.id]
del snipe_message_content[message.channel.id]

@bot.command(name="snipe")
async def snipe(ctx):
channel = ctx.channel
try: # This piece of code is run if the bot finds anything in the dictionary
em = discord.Embed(
name=f"Last deleted message in #{channel.name}",
description=snipe_message_content[ctx.change],
)
em.set_footer(
text=f"This message was sent by {snipe_message_author[channel.id]}"
)
await ctx.send(embed=em)
except: # This piece of code is run if the bot doesn't find anything in the dictionary
await ctx.send(f"There are no recently deleted messages in #{channel.name}")