[英]How to make a bot edit its own message on Discord
My friend wrote this amazing code for me but it doesn't seem to work.我的朋友为我编写了这个惊人的代码,但它似乎不起作用。 It's meant to send a message on a command then edit the message over and over again.
它意味着在命令上发送消息,然后一遍又一遍地编辑消息。 But when I run the code my terminal says
但是当我运行代码时,我的终端说
DiscordAPIError: Cannot edit a message authored by another user method: 'patch', path: '/channels/808300406073065483/messages/811398346853318668', code: 50005, httpStatus: 403
DiscordAPIError:无法编辑由其他用户方法创作的消息:'patch',路径:'/channels/808300406073065483/messages/811398346853318668',代码:50005,httpStatus:403
Is there a way to fix this problem?有没有办法解决这个问题?
client.on('message', userMessage =>
{
if (userMessage.content === 'hi')
{
botMessage = userMessage.channel.send('hi there')
botMessage.edit("hello");
botMessage.edit("what up");
botMessage.edit("sup");
botMessage.react(":clap:")
}
});
The Channel#send()
method returns a promise, meaning you must wait for the action to finish before being able to define it. Channel#send()
方法返回 promise,这意味着您必须等待操作完成才能定义它。 This can be done using either .then()
or async
and await
.这可以使用
.then()
或async
和await
来完成。 From personal preference, I regularly use the second option, although I have laid both options out for you.根据个人喜好,我经常使用第二个选项,尽管我已经为你列出了这两个选项。
client.on('message', async userMessage => {
if (userMessage.content === 'hi')
{
/*
botMessage = await userMessage.channel.send('hi there')
*/
userMessage.channel.send('hi there').then(botMessage => {
await botMessage.edit("hello");
await botMessage.edit("what up");
botMessage.edit("sup");
botMessage.react(":clap:")
})
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.