Techiio-author
Started by Allen ScottOct 31, 2021

Closed
discord python multiple times snipes

3 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 3 VIEWES SHARE

I have a discord python snipe bot but they only snipe once. I want it to be able to snipe multiple times. I want it do it with deque but I don't know how, as I'm new to Python.

import discord

from discord.ext import commands

bot.sniped_messages = {}

@bot.event

async def on_message_delete(message):

bot.sniped_messages[message.guild.id] = (message.content, message.author, message.channel.name, message.created_at)

@bot.command()

async def snipe(ctx):

try:

contents, author, channel_name, time = bot.sniped_messages[ctx.guild.id]

except:

await ctx.channel.send("er is geen verwijderde bericht Dombo!")

return

embed = discord.Embed(description=contents, color=discord.Color.red(), timestamp=time)

embed.set_author(name=f"{author.name}#{author.discriminator}", icon_url=author.avatar_url)

embed.set_footer(text=f"Deleted in : #{channel_name}")

await ctx.channel.send(embed=embed)

bot.run(TOKEN)

2 Replies

Techiio-commentatorMurray Thomson replied 4 months ago0 likes0 dislikes

Use a listing to keep all deleted messages:

import discord
from discord.ext import commands
bot = commands.Bot(prefix="-")
sniped_messages = {}
@bot.event
async def on_message_delete(message):
    history = sniped_messages.get(message.guild.id, [])
    history.insert(0, message)
    sniped_messages[message.guild.id] = history
@bot.command()
async def snipe(ctx, position):
    try:
        message = sniped_message[ctx.guild.id][position-1]
        
    except (KeyError, IndexError):
        await ctx.channel.send("er is geen verwijderde bericht Dombo!")
        return
    embed = discord.Embed(
        description=message.content,
        color=discord.Color.red(),
        timestamp=message.created_at
    )
    embed.set_author(name=f"{message.author}", icon_url=message.author.avatar_url)
    embed.set_footer(text=f"Deleted in : {message.channel}")
    await ctx.channel.send(embed=embed)
bot.run(TOKEN)

But I recommend that you create a #logs channel on your guild where your bot will send all deleted messages:

import discord
from discord.ext import commands
MY_GUILD_ID = 623204625251827724
LOGS_CHANNEL_ID = 626136590305198113
bot = commands.Bot(prefix="-")
@bot.event
async def on_message_delete(message):
    if message.guild.id != MY_GUILD_ID:
        return
    embed = discord.Embed(
        description=message.content,
        color=discord.Color.red(),
        timestamp=message.created_at
    )
    embed.set_author(name=f"{message.author}", icon_url=message.author.avatar_url)
    embed.set_footer(text=f"Deleted in : {message.channel}")
    logs = bot.get_channel(LOGS_CHANNEL_ID)
    await logs.send(embed=embed)
bot.run(TOKEN)

Techiio-commentatorAllen Scott replied 4 months ago0 likes0 dislikes

Thanks for ur recommendation I try it😊

This thread is closed by Allen Scott
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance