简体   繁体   English

在 discord.js 中编辑画布附件

[英]Editing Canvas Attachment in discord.js

I am trying to create a game of sorts using discord.js and Canvas.我正在尝试使用 discord.js 和 Canvas 创建各种游戏。 I recently learned of the Canvas from this tutorial: https://discordjs.guide/popular-topics/canvas.html .我最近从本教程中了解到 Canvas: https : //discordjs.guide/popular-topics/canvas.html I follow most of this example for creating the canvas.我按照这个例子的大部分来创建画布。

What I want to do is be able to edit the attachment, or replace it with a new one within a setInterval() .我想要做的是能够编辑附件,或在 setInterval() 中用新附件替换它。 I cannot seem to figure out how to edit the attachment, as I have already tried:我似乎无法弄清楚如何编辑附件,因为我已经尝试过:

//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);
});

I already know how to work with the canvas itself, as it is similar to the HTML5 canvas, but am unsure of how to manipulate this sent attachment.我已经知道如何使用画布本身,因为它类似于 HTML5 画布,但我不确定如何操作这个发送的附件。 If there is absolutely no way to edit this attachment, how would I delete the first attachment (the one given by attachid)?如果绝对无法编辑此附件,我将如何删除第一个附件(attachid 给出的附件)?

If you have any questions, or would like me to provide more code, please let me know!如果您有任何问题,或者希望我提供更多代码,请告诉我!

Discord API doesn't support message edition with another attachment. Discord API 不支持带有其他附件的消息版本。 So you can't add, remove or edit an attachment if the message has already been sent (you can try with your own account, it won't work).因此,如果邮件已经发送,您将无法添加、删除或编辑附件(您可以使用自己的帐户尝试,它不起作用)。 The only way you have is to delete the message and re-send it with another attachment...您拥有的唯一方法是删除该邮件并使用另一个附件重新发送...
There is a suggestion submitted to Discord here: https://support.discordapp.com/hc/en-us/community/posts/360041728292-Edit-sent-files这里有一个建议提交给 Discord: https : //support.discordapp.com/hc/en-us/community/posts/360041728292-Edit-sent-files

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM