Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.5 kB
3
Indexable
Never
import discord
from discord import app_commands
from discord.ui import Select
from discord.ui import View
from discord.ext import commands
import json


with open('config.json') as json_data:
    data_dict = json.load(json_data)
token = data_dict["token"]
prefix = data_dict["prefix"]
owner_id = data_dict["owner_id"]

class MainClient(discord.Client):
    def __init__(self):
        super().__init__(intents=discord.Intents.all())
        self.synced = False

    async def on_ready(self):
        await self.wait_until_ready()
        if not self.synced:
            await tree.sync(guild= discord.Object(id= 762354740210171964))
            self.synced = True
        print(f'We have logged in as {self.user}')



client = MainClient()
tree = app_commands.CommandTree(client)
@tree.command(name = "test", description = "testing", guild = discord.Object(id= 762354740210171964))
async def self(interaction: discord.Interaction, name: str):
    await interaction.response.send_message(f"Hello {name} ! I was made by Skydie !")

@tree.command(name = "embed", description= "Creates an embed message for you", guild = discord.Object(id= 762354740210171964))
async def self(interaction: discord.Interaction, title: str, message: str):

    select = Select(
        placeholder="Faites un choix",
        options=[
        discord.SelectOption(label="Modifier titre", emoji="✏️", description="Modifie le titre de l'embed"),
        discord.SelectOption(label="Modifier description", emoji= "📝", description="Modifie la description de l'embed")
    ])

    view = View()
    view.add_item(select)
    message2 = message
    title2 = title

    await interaction.response.send_message(embed = discord.Embed(
            title= title,
            description= message,
            color = discord.Colour.green()
        ), view= view)

    async def edit(interaction):



        if select.values[0] == "Modifier description":

            await interaction.channel.send('Veuillez envoyer votre nouvelle description')
            last_message = [message async for message in interaction.channel.history(limit=2)]

            def check(m):
                return m.author == interaction.user

            message = await client.wait_for("message", check=check)
            await last_message[0].delete()
            await last_message[1].delete()
            message2 = message.content
            await interaction.channel.send(embed=discord.Embed(
                title=title2,
                description=message2,
                color=discord.Colour.green())
                , view=view)


            await message.delete()



        elif select.values[0] == "Modifier titre":

            await interaction.channel.send('Veuillez envoyer votre nouveau titre')
            last_message = [message async for message in interaction.channel.history(limit=2)]

            def check(m):
                return m.author == interaction.user

            message = await client.wait_for("message", check=check)
            await last_message[0].delete()
            await last_message[1].delete()


            title2 = message.content
            await interaction.channel.send(embed=discord.Embed(
                title=message.content,
                description=message2,
                color=discord.Colour.green())
                , view=view)
            await message.delete()


    select.callback = edit


client.run(token)