为什么这个不和谐斜杠命令不起作用?



我正在尝试用斜杠命令升级我所有的不和谐机器人,使用discord_slash包(我相信现在称为discord_interactions)。但是,当我运行下面的代码时,每次我使用斜杠命令时,它都会显示"此交互失败"。不和。调试器和一些调试文本也证明与命令相关的函数根本没有运行。这是我的代码(我认为我正在做的按钮是错误的,但在这种情况下,这应该无关紧要):为什么这种互动会失败?


import discord
import discord_slash
from discord.types.components import ButtonComponent
from discord_slash import SlashCommand
from discord.ui import Button
bot = discord.Client(intents=discord.Intents.all())
slash = SlashCommand(bot, sync_commands=True)

@bot.event
async def on_ready():
print("we a'goin!")

guild_ids = ['guild id']
normalPollOptions = [
{
"name": "poll_title",
"description": "Title of the Poll",
"type": 3,
"required": True
},
{
"name": "option_1",
"description": "First choice of the poll",
"type": 3,
"required": True
},
{
"name": "option_2",
"description": "Second choice of the poll",
"type": 3,
"required": True
},
{
"name": "option_3",
"description": "Third choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_4",
"description": "Fourth choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_5",
"description": "Fifth choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_6",
"description": "Sixth choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_7",
"description": "Seventh choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_8",
"description": "Eighth choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_9",
"description": "Ninth choice of the poll",
"type": 3,
"required": False
},
{
"name": "option_10",
"description": "Tenth choice of the poll",
"type": 3,
"required": False
}
]

@slash.slash(name="normalpoll", description="Make a normal poll", guild_ids=guild_ids, options=normalPollOptions)
async def _normalpoll(ctx, poll_title, option_1, option_2, option_3=None, option_4=None, option_5=None, option_6=None, option_7=None, option_8=None, option_9=None, option_10=None):
await ctx.send(content="hi!")
optionParam = [option_1, option_2, option_3, option_4, option_5, option_6, option_7, option_8, option_9, option_10]
options = [i for i in optionParam if not i is None]
buttonList = [Button(label=i) for i in options]
await ctx.send(components=buttonList)

bot.run('censored bot token')

谢谢!

选项实际上应该采用不同的格式才能使它们工作

您必须使用discord_slash.utils.manage_commandscreate_option功能来为您的命令创建一个选项

import discord
import discord_slash
from discord.types.components import ButtonComponent
from discord_slash.utils.manage_commands import create_option
from discord_slash import SlashCommand
from discord.ui import Button
bot = discord.Client(intents=discord.Intents.all())
slash = SlashCommand(bot, sync_commands=True)

@bot.event
async def on_ready():
print("we a'goin!")

guild_ids = ['guild id']
normalPollOptions = [
create_option(
name="poll_title",
description="Title of the Poll",
type=3,
required=True
),
create_option(
name="option_1",
description="First choice of the poll",
type=3,
required=True
),
create_option(
name="option_2",
description="Second choice of the poll",
type=3,
required=True
),
create_option(
name="option_3",
description="Third choice of the poll",
type=3,
required=False
),
create_option(
name="option_4",
description="Fourth choice of the poll",
type=3,
required=False
),
create_option(
name="option_5",
description="Fifth choice of the poll",
type=3,
required=False
),
create_option(
name="option_6",
description="Sixth choice of the poll",
type=3,
required=False
),
create_option(
name="option_7",
description="Seventh choice of the poll",
type=3,
required=False
),
create_option(
name="option_8",
description="Eighth choice of the poll",
type=3,
required=False
),
create_option(
name="option_9",
description="Ninth choice of the poll",
type=3,
required=False
),
create_option(
name="option_10",
description="Tenth choice of the poll",
type=3,
required=False
)
]
@slash.slash(name="normalpoll", description="Make a normal poll", guild_ids=guild_ids, options=normalPollOptions)
async def _normalpoll(ctx, poll_title, option_1, option_2, option_3=None, option_4=None, option_5=None, option_6=None, option_7=None, option_8=None, option_9=None, option_10=None):
await ctx.send("hi!")
optionParam = [option_1, option_2, option_3, option_4, option_5, option_6, option_7, option_8, option_9, option_10]
options = [i for i in optionParam if not i is None]
buttonList = [Button(label=i) for i in options]
await ctx.send(components=buttonList)
bot.run('censored bot token')

告诉我你是否可以…

相关内容

  • 没有找到相关文章