【发布时间】:2020-04-08 13:27:02
【问题描述】:
我正在尝试使用 discord.js 和 Canvas 创建各种游戏。我最近从本教程中了解到了 Canvas:https://discordjs.guide/popular-topics/canvas.html。我按照这个示例的大部分内容来创建画布。
我想要做的是能够编辑附件,或者用 setInterval() 中的新附件替换它。我似乎无法弄清楚如何编辑附件,因为我已经尝试过:
//attachid = The id for the canvas attachment; channel is the name of the channel the canvas was set in
bot.login(token).then(() => {
setInterval(function() { //Start an interval after logging in...
if(canvas !== null) { //If the canvas was created...
//Edit canvas here
var attachment = new Discord.Attachment(canvas.toBuffer) //Create a new canvas attachment
//The fetchMessage below is where I am having issue
channel.fetchMessage(attachid).then(msg => msg.edit(attachment));
}
}, 1000);
});
我已经知道如何使用画布本身,因为它类似于 HTML5 画布,但我不确定如何操作这个发送的附件。如果绝对无法编辑此附件,我将如何删除第一个附件(attachid 给出的那个)?
如果您有任何问题,或者希望我提供更多代码,请告诉我!
【问题讨论】:
标签: node.js canvas discord.js