【问题标题】:Editing Canvas Attachment in discord.js在 discord.js 中编辑画布附件
【发布时间】: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


    【解决方案1】:

    Discord API 不支持带有其他附件的消息编辑。因此,如果消息已经发送,则无法添加、删除或编辑附件(您可以使用自己的帐户尝试,它不会起作用)。您唯一的方法是删除邮件并使用另一个附件重新发送...
    这里有一个提交给 Discord 的建议: https://support.discordapp.com/hc/en-us/community/posts/360041728292-Edit-sent-files

    【讨论】:

    • 感谢您通知我。我真的认为 Discord 至少应该对这些附件进行某种形式的删除,但版本可以打开更多的机会。
    猜你喜欢
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    相关资源
    最近更新 更多