UnhandledPromiseRejectionWarning:DiscordAPIError:无法编辑由其他用户创作的消息

时间:2021-04-21 03:12:52

标签: javascript discord discord.js bots

我正在做一个项目,基本上我试图让音乐不和谐机器人播放我创建的播放列表。这是不和谐的javascript并且正在使用npm。

exports.run = async (client, message, args) => {

    if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

    if (!args[0]) return message.channel.send(`${client.emotes.error} - Please indicate the title of a song !`);
    

    message.edit('**!play hello**')

    client.player.play(message, args.join(" "), { firstResult: true });

};

此外,我知道没有办法实际编辑消息,但是,我控制了机器人,所以我可以使用机器人 ID 或其他东西来更改可变消息吗?任何想法都会非常感谢!

1 个答案:

答案 0 :(得分:0)

您不能编辑不是由机器人创作的消息,参数 message 正在处理程序的箭头函数中导出,该函数声明用户而非机器人发送的消息/命令,以编辑bot 的消息,您可以应用以下更改:

 message.channel.send(`${client.emotes.error} - Please indicate the title of a song !`).then((editthis) => {
   editthis.edit(`Looks like we have an edited message now`)
 }); 

基本上 <TextChannel>.send() 方法返回一个带有已发送消息对象的承诺,这里我们将对象定义为 editthis 并进一步使用我们在解析过程中传递的 editthis 参数来解析承诺和编辑它(我们要编辑的消息对象)。