斜杠命令选项出现问题.Discord.py



我在斜杠命令选项方面遇到了问题,即我正在尝试设置输入数字的最小值和最大值。

@bot.tree.command(name="test")
@app_commands.Argument(
num=[
app_commands.Argument.min_value(1),
app_commands.Argument.min_value(5)
]
)
async def test(interaction: discord.Interaction, num:int):
await interaction.response.send_message(f"You choose number: {num}")

控制台日志:

Traceback (most recent call last):
File "e:derekbot!srcbot.py", line 81, in <module>
app_commands.Argument.min_value(1),
TypeError: 'member_descriptor' object is not callable

我也试过用其他方法来做,但它们也不起作用。

mate。

我想我已经找到了解决办法。您可以只使用app_commands.Range类来设置最小值和最大值。

@bot.tree.command()
async def test(ctx: discord.Interaction, value: app_commands.Range[int, 5]):
await ctx.response.send_message(f"Your number: {value}")
  • Range[int, 10]表示最小值为10,没有最大值
  • Range[int, None, 10]表示最大值为10,没有最小值
  • Range[int, 1, 10]表示最小值为1,最大值为10

这应该根据文档进行修复,您需要在装饰器中设置属性,而不是像以前那样调用它。

@bot.tree.command(name="test")
@app_commands.Argument(
name="num",
min_value=1,
max_value=5
)
async def test(interaction: discord.Interaction, num: int):
await interaction.response.send_message(f"You choose number: {num}")

你可以在这里找到文档。

我还建议你坚持使用不和谐.py.

最新更新