gpt4 book ai didi

javascript - 使用discord.js 编辑消息不起作用

转载 作者:行者123 更新时间:2023-11-30 09:32:49 26 4
gpt4 key购买 nike

这个问题让我头疼。

我正在尝试编辑不和谐消息,但它不起作用。

我收到错误:slotDisplayer.edit 不是函数

exports["%slots play"] = function(args, data) {
var frame_count = utils.getRandomInt(15, 25);
var main_reels = utils.newReels(3);
var slotDisplayer = data.channel.send(`You spent 1📀 on this slot.\n\nSpinning...`);
slotDisplayer.then(function(msg){
utils.nextFrame(main_reels, 0, 0, frameDisplay);
return msg;
}).catch(function(err){
console.log(err);
});
console.log(slotDisplayer);
function frameDisplay(res) {
var f = res.frame;
console.log(slotDisplayer);
console.log(`|${f[0][0]} | ${f[0][1]} | ${f[0][2]} |\n|${f[1][0]} | ${f[1][1]} | ${f[1][2]} |\n|${f[2][0]} | ${f[2][1]} | ${f[2][2]} |`);
slotDisplayer.edit(utils.generateFrame()).catch(function(err){
console.log(err);
});
if(frame_count > res.frame_index){
var properIndex = res.index >= main_reels[0].length - 2 ? 0 : res.index;
setTimeout(function(){utils.nextFrame(main_reels, properIndex,res.frame_index,frameDisplay);}, 200);
} else {
var payobj = utils.logic(res.frame);
slotDisplayer.edit(`|${f[0][0]} | ${f[0][1]} | ${f[0][2]} |\n|${f[1][0]} | ${f[1][1]} | ${f[1][2]} |\n|${f[2][0]} | ${f[2][1]} | ${f[2][2]} |\n${payobj.message}`);
}
}
}

我需要一个在discord.js 中编辑消息的示例。

最佳答案

您将需要使用 .then()。

data.channel.send("blah blah").then((msg)=>{
//your code here! msg.edit will work here.
})

这是因为channel.send()返回一个Promise,根据API:https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=send

此外,您可以将消息对象分配给 .then() 中的另一个变量,这样您就不必处理大量尴尬的缩进。

关于javascript - 使用discord.js 编辑消息不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45292707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com