gpt4 book ai didi

javascript - 如何让机器人在 Discord 上编辑自己的消息

转载 作者:行者123 更新时间:2023-12-04 08:04:02 25 4
gpt4 key购买 nike

我的 friend 为我写了这个惊人的代码,但它似乎不起作用。它旨在根据命令发送消息,然后一遍又一遍地编辑消息。但是当我运行代码时,我的终端说

DiscordAPIError: Cannot edit a message authored by another user method: 'patch', path: '/channels/808300406073065483/messages/811398346853318668', code: 50005, httpStatus: 403


有没有办法解决这个问题?
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:")
}
});

最佳答案

Channel#send()方法返回一个 promise ,这意味着您必须等待操作完成才能定义它。这可以使用 .then() 来完成。或 asyncawait .根据个人喜好,我经常使用第二个选项,尽管我已经为您列出了两个选项。
最终代码

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:")
})
}
});

关于javascript - 如何让机器人在 Discord 上编辑自己的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66311229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com