discord.py-互动 - 按钮
我一直在尝试为我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Istal
discord_components
模块。pip install discord_components
此代码应该对您有用:
Instal the
discord_components
Module .pip install discord_components
Then this code should work for you :