Skip to content

Instantly share code, notes, and snippets.

@enzomtpYT
Last active May 13, 2024 22:38
Show Gist options
  • Save enzomtpYT/09ed652d07dcefc3d925931e4b96e50b to your computer and use it in GitHub Desktop.
Save enzomtpYT/09ed652d07dcefc3d925931e4b96e50b to your computer and use it in GitHub Desktop.
Discord messager logger selfbot python (don't support polls)
from discord.ext import commands
from discord_webhook import DiscordWebhook, DiscordEmbed
import requests, os, datetime
print("Version 2.0 by enzomtp")
webhook_url = ""
# Verify and create count.txt file if it doesn't exist
if not os.path.exists("count.txt"):
with open("count.txt", "w") as file:
file.write("0")
# create temp folder if it doesn't already exists or empty it if it does
if not os.path.exists("temp"):
os.makedirs("temp")
else:
for file in os.listdir("temp"):
os.remove(f"temp/{file}")
bot = commands.Bot("jaha>", self_bot=True)
@bot.command()
async def count(c):
with open("count.txt", "r") as file:
count = file.read()
await c.send(count)
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
@bot.event
async def on_message_delete(c):
with open("count.txt", "r+") as file:
count = int(file.read())
count += 1
file.seek(0)
file.write(str(count))
file.truncate()
webhook = DiscordWebhook(url=webhook_url, content=c.content)
embed = DiscordEmbed()
embed.title = "Deleted Message"
embed.description = "Infos below"
embed.color = 16711680
embed.add_embed_field(name="User details", value=f"User ID : {c.author.id}\nUsername (Server) : {c.author.display_name}\nUsername (Global) : {c.author.display_name} \nUser pfp (Server) : [Link]({c.author.display_avatar})\nUser pfp (Global) : [Link]({c.author.avatar})")
embed.add_embed_field(name="Message details", value=f"Message ID : {c.id}\nMessage timestamp : {c.created_at}")
embed.add_embed_field(name="Attachment details", value=f"Attachment count : {len(c.attachments)}\nAttachment URLs : {[attachment.url for attachment in c.attachments]}", inline=False)
embed.set_author(name=f"{c.author.display_name}", icon_url=f"{c.author.display_avatar}")
embed.set_timestamp()
if c.attachments:
attachment_urls = []
for attachment in c.attachments:
response = requests.get(attachment.url)
if response.status_code == 200:
file_name = os.path.basename(attachment.filename)
with open(f"temp/{file_name}", "wb") as file:
file.write(response.content)
with open(f"temp/{file_name}", "rb") as file:
filedata = file.read()
webhook.add_file(file=filedata, filename=attachment.filename)
else:
print(f"Failed to download attachment: {attachment.url}")
if c.guild is not None:
embed.add_embed_field(name="Server details", value=f"Server ID : {c.guild.id}\nServer name : {c.guild.name}\nServer icon : [Link]({c.guild.icon})\nMember count : {c.guild.member_count}")
embed.add_embed_field(name="Channel details", value=f"Channel ID : {c.channel.id}\nChannel name : {c.channel.name}\nChannel type : {c.channel.type}")
webhook.add_embed(embed)
response = webhook.execute()
if response.status_code == 204:
print("Webhook sent successfully")
else:
print("Failed to send webhook")
print(response.text)
for file in os.listdir("temp"):
os.remove(f"temp/{file}")
@bot.event
async def on_message_edit(before, after):
if before.content == after.content and before.attachments == after.attachments:
return
webhook = DiscordWebhook(url=webhook_url, content=f"**Before:** {before.content}\n**After:** {after.content}")
embed = DiscordEmbed()
embed.title = "Edited Message"
embed.description = "Infos below"
embed.color = 16776960
embed.add_embed_field(name="User details", value=f"User ID : {before.author.id}\nUsername (Server) : {before.author.display_name}\nUsername (Global) : {before.author.display_name} \nUser pfp (Server) : [Link]({before.author.display_avatar})\nUser pfp (Global) : [Link]({before.author.avatar})")
embed.add_embed_field(name="Message details", value=f"Message ID : {before.id}\nMessage timestamp : {before.created_at}")
embed.add_embed_field(name="Attachment details", value=f"Attachment count : {len(before.attachments)}\nAttachment URLs : {[attachment.url for attachment in before.attachments]}", inline=False)
embed.set_author(name=f"{before.author.display_name}", icon_url=f"{before.author.display_avatar}")
embed.set_timestamp()
if before.guild is not None:
embed.add_embed_field(name="Server details", value=f"Server ID : {before.guild.id}\nServer name : {before.guild.name}\nServer icon : [Link]({before.guild.icon})\nMember count : {before.guild.member_count}")
embed.add_embed_field(name="Channel details", value=f"Channel ID : {before.channel.id}\nChannel name : {before.channel.name}\nChannel type : {before.channel.type}")
if before.attachments:
attachment_urls = []
for attachment in before.attachments:
response = requests.get(attachment.url)
if response.status_code == 200:
file_name = os.path.basename(attachment.filename)
with open(f"temp/{file_name}", "wb") as file:
file.write(response.content)
with open(f"temp/{file_name}", "rb") as file:
filedata = file.read()
webhook.add_file(file=filedata, filename=attachment.filename)
else:
print(f"Failed to download attachment: {attachment.url}")
webhook.add_embed(embed)
response = webhook.execute()
if response.status_code == 204:
print("Webhook sent successfully")
else:
print("Failed to send webhook")
print(response.text)
for file in os.listdir("temp"):
os.remove(f"temp/{file}")
bot.run("")
@enzomtpYT
Copy link
Author

enzomtpYT commented May 11, 2024

Modify TOKEN at the very last line for it to work
And webhook url at line 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment