discord.py-互动 - 按钮

发布于 2025-02-11 14:49:59 字数 672 浏览 3 评论 0原文

我一直在尝试为我的Discord机器人创建按钮,但是看来我有问题,我只是无法弄清楚它是什么。

这是我目前拥有的代码:

@bot.command()
async def test(ctx: interactions.CommandContext):
    button = Button(
        style=ButtonStyle.PRIMARY,
        custom_id="primary",
        label="Blue button",
    )
    await ctx.send("Hello World!", components=button)

我也有以下导入:

import discord
from discord.ext import commands
import random
import time
import interactions
from interactions import Button, ButtonStyle, SelectMenu, SelectOption, ActionRow

我期望的:bot回复命令!用消息“你好!”测试!和一个带有文本“蓝色按钮”的按钮。

它的作用:绝对没有。

现在我已经盯着这个了很长一段时间了,所以我错过了一些简单的机会,但是我很高兴任何帮助:)

I've been trying to create Buttons for my Discord bot but it seems like I have something wrong, I just can't figure out what it is.

Here's the code I currently have:

@bot.command()
async def test(ctx: interactions.CommandContext):
    button = Button(
        style=ButtonStyle.PRIMARY,
        custom_id="primary",
        label="Blue button",
    )
    await ctx.send("Hello World!", components=button)

I also have the following imports:

import discord
from discord.ext import commands
import random
import time
import interactions
from interactions import Button, ButtonStyle, SelectMenu, SelectOption, ActionRow

What I expect: The bot replying to command !test with the message "Hello World!" and a button with the text 'Blue button' attached to that message.

What it does: Absolutely nothing.

Now I have been staring at this for quite a while, so fair chance I've missed something rather simple, but I'd appreciate the help either way :)

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

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

发布评论

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

评论(1

为人所爱 2025-02-18 14:49:59

Istal discord_components模块。
pip install discord_components

此代码应该对您有用:

from discord_components import *

bot = ComponentsBot(command_prefix="?")

@bot.command()
async def test(ctx):
    button = Button(
        style=ButtonStyle.blue,
        custom_id="primary",
        label="Blue button",
    )
    await ctx.send("Hello World!", components=[button])

Instal the discord_components Module .
pip install discord_components

Then this code should work for you :

from discord_components import *

bot = ComponentsBot(command_prefix="?")

@bot.command()
async def test(ctx):
    button = Button(
        style=ButtonStyle.blue,
        custom_id="primary",
        label="Blue button",
    )
    await ctx.send("Hello World!", components=[button])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文