我正在制作一个discord的机器人,可以获得不同平台上的游戏的玩家数量.我希望能够让它有一个称为/count steam的命令,它将返回游戏的玩家计数.我已经将其设置为执行此操作,但我不知道如何在斜杠命令中添加空格.我看到其他机器人都有它,所以它是这样的:/command game <arg>这是我当前的斜杠命令代码(显然我有所有其他机器人的东西):

@bot.tree.command(name="count", description = "Gorilla Tag's steam player count")
async def count_steam(interaction: discord.Interaction):
    await interaction.response.send_message(getSteamPlayers())

无论何时运行此命令,我都会收到以下错误:

Traceback (most recent call last):
  File "D:\Gorilla Bot\main.py", line 93, in <module>
    async def count_steam(interaction: discord.Interaction):
  File "C:\Users\Sensor\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\app_commands\tree.py", line 887, in decorator
    command = Command(
  File "C:\Users\Sensor\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\app_commands\commands.py", line 644, in __init__
    self.name: str = validate_name(name)
  File "C:\Users\Sensor\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\app_commands\commands.py", line 191, in validate_name
    raise ValueError(
ValueError: 'count steam' must be between 1-32 characters and contain only lower-case letters, numbers, hyphens, or underscores.

我使用的是最新版本的discord.py.我还将这些用于不一致模块导入(如果有帮助):

import discord
from discord import app_commands
from discord.ext import commands

推荐答案

您应该使用名为countGroup,其中包含名为steamCommand.这样,您就可以使用/count steam调用所需的命令.

import discord
from discord import app_commands
from discord.ext import commands

count_group = app_commands.Group(name="count", description="Count something.")

@count_group.command(name="steam", description="Gorilla Tag's steam player count")
async def count_steam(interaction: discord.Interaction):
    await interaction.response.send_message(getSteamPlayers())

# Add group in the bot's command tree
bot.tree.add_command(count_group)

Python相关问答推荐

Pandas 修改原始excel

Gekko解算器错误results.json未找到,无法找出原因

如何循环循环的每个元素并过滤掉Python rame中的条件

Numpy索引argsorted使用integer数组,同时保留排序顺序

如何让pyparparsing匹配1天或2天,但1天和2天失败?

数字梯度的意外值

Polars:使用列值引用when / then表达中的其他列

Chatgpt API不断返回错误:404未能从API获取响应

Python 3.12中的通用[T]类方法隐式类型检索

仿制药的类型铸造

为什么我的Python代码在if-else声明中的行之前执行if-else声明中的行?

发生异常:TclMessage命令名称无效.!listbox"

在Python中管理打开对话框

为什么默认情况下所有Python类都是可调用的?

NP.round解算数据后NP.unique

如果满足某些条件,则用另一个数据帧列中的值填充空数据帧或数组

如何在Python中找到线性依赖mod 2

改进大型数据集的框架性能

网格基于1.Y轴与2.x轴显示在matplotlib中

为什么'if x is None:pass'比'x is None'单独使用更快?