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

Question:

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!")
Asked By: Sphe

||

Answers:

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")
Answered By: Shweta K

interaction.user (for user)
interaction.user.id (for user id)

Answered By: Akitoo
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.