首页 > 解决方案 > 为什么我不断收到交互失败 (discord.py)

问题描述

我正在过渡到斜线命令,它们令人头疼。我已经在椅子上坐了一个多小时。这是测试斜杠命令。

@slash.slash(name="test",
             description="This is just a test command, nothing more.")
async def _test(ctx):
    await ctx.channel.send("Hello World!")

我做了这个测试斜线命令,看看它是否有效。长话短说,它没有。我的意思是,它出现了,但它实际上并没有做任何事情。它只是说“交互失败”。这不是唯一的问题,描述也不存在。它只是显示标题,老实说,我不想死去试图解决这个问题。这是我导入的内容:

import discord
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_choice, create_option

我想我应该提到我没有得到任何错误,这是一件坏事。任何帮助将不胜感激。

标签: pythonjsondiscorddiscord.py

解决方案


当您响应消息时,您应该使用它ctx.send来响应交互,而不是ctx.channel.send向通道发送 POST 请求。如果您不响应交互,则会收到交互失败消息。

您也可以使用ctx.defer回复,否则您最多可以有 15 分钟的时间回复您的互动。


推荐阅读