我的代码需要一些帮助,除了此交互在 Discord 中失败之外,我没有收到任何错误。
我用于斜线命令的代码:
name: "random",
description: "Random Message",
options: [],
async execute(_bot, say, interaction) {
var facts = ["test1", "test2", "test3", "test4"];
var fact = Math.floor(Math.random() * facts.length);
await say(interaction, facts[fact]);
},
};
适用于我的前缀和非斜杠命令的代码:
exports.run = async (client, message, args) => {
var facts = ["test", "test2", "test3"];
var fact = Math.floor(Math.random() * facts.length);
message.channel.send(facts[fact]);
}```
答案 0 :(得分:0)
我遇到了这个问题,所以我再次查看了 API 文档,发现当我向通道发送响应时,我实际上并没有响应交互。要响应交互,您必须使用交互 ID 和令牌将数据发送到 webhook。来自文档:
url = "https://discord.com/api/v8/interactions/<interaction_id>/<interaction_token>/callback"
json = {
"type": 4,
"data": {
"content": "Congrats on sending your command!"
}
}
r = requests.post(url, json=json)
在此处查看更多信息:https://discord.com/developers/docs/interactions/slash-commands#responding-to-an-interaction