【问题标题】:UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another userUnhandledPromiseRejectionWarning:DiscordAPIError:无法编辑由其他用户创作的消息
【发布时间】:2021-07-15 05:38:42
【问题描述】:

我正在做一个项目,基本上我试图让音乐不和谐机器人播放我创建的播放列表。这是不和谐的 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 或其他东西来更改可变消息吗?任何想法都会非常感谢!

【问题讨论】:

  • 如果您不是邮件的所有者/发件人,则无法编辑该邮件。

标签: javascript discord discord.js bots


【解决方案1】:

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

 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()方法返回一个带有发送消息对象的promise,这里我们将对象定义为editthis,进一步我们解析promise并使用我们在解析它时传递的editthis参数进行编辑(我们的消息是编辑过的对象)。

【讨论】:

  • 谢谢我的人,真的很感激,有一个问题,有没有办法阻止“看起来我们现在有一个编辑过的消息”打印出来?非常感谢,你是一个救生员。
  • 只需在.edit() 方法中替换它,如果有帮助,您可以将我的答案标记为正确:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-14
  • 2020-12-20
  • 2021-05-05
  • 2020-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多