Home > Blockchain >  I want to see who clicked the button on Discord.py, how do I do?
I want to see who clicked the button on Discord.py, how do I do?

Time:06-24

I'm making a bot for my Discord server, and I'd like to see who clicks the button for a little project. Can anyone help me?

async def bottoni(ctx):
    await buttons.send(
        content = "click!",
        channel = ctx.channel.id,
        components = [
            ActionRow([
                Button(
                    label="first",
                    style=ButtonType().Success,
                    custom_id = "button_one"
                ),
                Button(
                    label="second",
                    style=ButtonType().Danger,
                    custom_id = "button_two"
                )
            ])
        ]
    )

@buttons.click
async def button_one(ctx):
    interaction = buttons.click
    print(interaction.author, " clicked!")

@buttons.click
async def button_two(ctx):
    interaction = buttons.click
    print(interaction.author, " clicked!")

CodePudding user response:

Reading the docs Docs

So here is your code

sync def bottoni(ctx):
    await buttons.send(
        content = "click!",
        channel = ctx.channel.id,
        components = [
            ActionRow([
                Button(
                    label="first",
                    style=ButtonType().Success,
                    custom_id = "button_one"
                ),
                Button(
                    label="second",
                    style=ButtonType().Danger,
                    custom_id = "button_two"
                )
            ])
        ]
    )

@buttons.click
async def button_one(ctx):
    interaction = buttons.click
    print(f"{ctx.member.name} just  clicked! button one")

@buttons.click
async def button_two(ctx):
    interaction = buttons.click
    print(f"{ctx.member.name} just  clicked! button two")
  • Related