未处理的PromiseRejection警告:DiscordAPI错误:无法编辑其他用户编写的消息



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

您可能无法编辑非机器人程序编写的消息-参数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,然后我们使用在解析过程中传递的editthis参数(我们的待编辑消息对象(解析promise并进行编辑。

相关内容

最新更新