Untitled
unknown
plain_text
2 years ago
1.8 kB
11
Indexable
import discord
from discord.ext import commands
import json
intents = discord.Intents.default()
intents.guilds = True
intents.guild_messages = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
@bot.event
async def on_message(message):
if message.content == "!embed":
embed = discord.Embed(
title="Cliquez sur la réaction",
description="Cliquez ci-dessous pour enregistrer votre ID.",
color=0x007BFF,
timestamp=message.created_at,
)
sent_embed = await message.channel.send(embed=embed)
await sent_embed.add_reaction("💾") # Add the "save" reaction
@bot.event
async def on_raw_reaction_add(payload):
if payload.emoji.name == "💾":
channel = bot.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
if message and message.author == bot.user and message.embeds:
user_id = payload.user_id
embed_text = message.embeds[
0
].description # Get the description text of the embed
# Load existing data from data.json
try:
with open("data.json", "r") as file:
data = json.load(file)
except FileNotFoundError:
data = []
# Update the list with the new entry
data.append(
{
"user_id": user_id,
"embed_text": embed_text,
"timestamp": str(message.created_at),
}
)
# Save the updated data back to data.json
with open("data.json", "w") as file:
json.dump(data, file, indent=4)
bot.run("BOT_TOKEN")
Editor is loading...