admin管理员组文章数量:1306684
Ive got my bot running with some new code but it cant edit any messages using message.edit()
throws a DiscordAPIError
Any help would be appreciated.
Heres my code for my super simple bot
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', message => {
if (message.content === 'lenny') {
message.edit('( ͡° ͜ʖ ͡°)');
}
});
client.login('Censored to protect identity');
This is the console output whenever someone says 'lenny' in a text channel.
(node:6672) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user
at C:\Users\Terra Byte\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
at C:\Users\Terra Byte\node_modules\snekfetch\src\index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:6672) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
I have tried giving the role administrator on the server, but it still throws the same DiscordAPIError
error.
Ive got my bot running with some new code but it cant edit any messages using message.edit()
throws a DiscordAPIError
Any help would be appreciated.
Heres my code for my super simple bot
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', message => {
if (message.content === 'lenny') {
message.edit('( ͡° ͜ʖ ͡°)');
}
});
client.login('Censored to protect identity');
This is the console output whenever someone says 'lenny' in a text channel.
(node:6672) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user
at C:\Users\Terra Byte\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
at C:\Users\Terra Byte\node_modules\snekfetch\src\index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:6672) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
I have tried giving the role administrator on the server, but it still throws the same DiscordAPIError
error.
2 Answers
Reset to default 3The reason that error is being thrown is because your trying to edit another users message.
client.on('message', message => {
if (message.content === 'lenny') {
message.edit('( ͡° ͜ʖ ͡°)'); // <-- Here you are editing another users message.
}
});
The message you are trying to edit belongs to the person who authored the message, and you cannot edit other users messages. As you stated above, you wanted it to delete the message, so I'll implement that below.
client.on('message', message => {
if (message.content === 'lenny') {
message.delete() //This is the original message that triggered the message event.
message.channel.send("( ͡° ͜ʖ ͡°)") //Send a lenny face in response to the user saying "lenny"
}
});
You don't need to search for it, just use the definition of message in your message event.
As an alternative option to what you're asking for but can't do, you can have the bot post a new message when someone posts "!lenny", through message.channel.send()
. Or you can make it even easier and create a custom Emoji for your server that shows a lenny face in the place of :lenny:, something like this: https://discordemoji./emoji/Lenny
本文标签:
版权声明:本文标题:javascript - Cant edit messages with discord bot (UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message autho 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741823766a2399523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论