使用 discord.js 编辑消息无效
Editing messages using discord.js not working
这个问题很头疼
我正在尝试编辑不和谐消息,但它不起作用。
我收到错误: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() returns 一个 Promise,根据 API: https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=send
此外,您可以将消息对象分配给 .then() 中的另一个变量,这样您就不必处理大量笨拙的缩进。
这个问题很头疼
我正在尝试编辑不和谐消息,但它不起作用。
我收到错误: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() returns 一个 Promise,根据 API: https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=send
此外,您可以将消息对象分配给 .then() 中的另一个变量,这样您就不必处理大量笨拙的缩进。