You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.py 带参数Slash Command无响应问题求助

Discord斜杠命令添加参数后无响应的解决办法

我给Discord机器人的斜杠命令加了一个字符串参数后,命令完全无法工作,输入/attendance something时Discord提示“The application did not respond”,但无参数的版本能正常运行。

无参数的正常代码

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

class AttendanceCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    
    @app_commands.command(description='see which rolemembers are in your voicechannel')
    async def attendance(self, interaction: discord.Interaction):
        await interaction.response.send_message(f"Attendance command received without parameter")

async def setup(bot):
    await bot.add_cog(AttendanceCog(bot))

添加参数后失效的代码

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

class AttendanceCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    
    @app_commands.command(description='see which rolemembers are in your voicechannel')
    @app_commands.describe(test='test')
    async def attendance(self, interaction: discord.Interaction, test: str):
        await interaction.response.send_message(f"Attendance command received with parameter: {test}")
        
async def setup(bot):
    await bot.add_cog(AttendanceCog(bot))

解决步骤

  • 重新同步斜杠命令到Discord服务器
    修改命令参数后,Discord服务器端的命令定义不会自动更新,必须手动同步。可以在机器人的on_ready事件里添加同步逻辑,测试阶段建议用服务器专属同步(即时生效):

    @bot.event
    async def on_ready():
        print(f'Logged in as {bot.user}')
        # 替换成你的服务器ID
        await bot.tree.sync(guild=discord.Object(id=1234567890))
        print("命令已同步")
    

    如果用全局同步(去掉guild参数),Discord最多需要1小时才能生效。

  • 检查机器人控制台的错误日志
    运行机器人时打开控制台,查看是否有未捕获的异常。比如机器人可能缺少发送消息的权限,或者参数处理时出现错误,这些都会导致无法响应交互。

  • 确认Discord端命令已更新
    在Discord里输入/attendance,如果没有弹出参数输入框,说明命令同步未成功,需要重新执行同步操作。

内容的提问来源于stack exchange,提问作者SilverSkips

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 20:52:09