我想看看谁单击了Discord.py上的按钮,我该怎么办?

发布于 2025-02-08 18:22:02 字数 843 浏览 1 评论 0原文

我正在为我的Discord服务器制作一个机器人,我想看看谁单击一个小项目的按钮。谁能帮我吗?

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!")

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!")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

征棹 2025-02-15 18:22:02

阅读文档

所以这是您的代码

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")

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")
何时共饮酒 2025-02-15 18:22:02

您可以使用interaction.user检索用户,并且可以使用互动。

You can use interaction.user to retrieve the user and you can use interaction.user.id to get the ID of said user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文