Skip to content
How to code a discord snipe command -_-
Profile icon
efgabc

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

You are viewing a single comment. View All
Profile icon
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}")