Cant edit messages with discord bot (UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user)
Cant edit messages with discord bot (UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user)
我有我的机器人 运行 一些新代码,但它无法使用 message.edit()
编辑任何消息抛出 DiscordAPIError
任何帮助将不胜感激。
这是我的超级简单机器人的代码
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');
这是每当有人在文本频道中说 'lenny' 时的控制台输出。
(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)
我已经尝试在服务器上赋予管理员角色,但它仍然抛出相同的 DiscordAPIError
错误。
根本无法在 Discord 中编辑来自其他用户的消息,even/especially 使用 API。
作为您要求但无法做到的替代选项,您可以让机器人 post 在有人 post 发送“!lenny”时通过 message.channel.send()
。或者你可以让它更容易,为你的服务器创建一个自定义表情符号,在 :lenny: 的地方显示一个 lenny 的脸,像这样:https://discordemoji.com/emoji/Lenny
引发错误的原因是您试图编辑另一个 用户消息。
client.on('message', message => {
if (message.content === 'lenny') {
message.edit('( ͡° ͜ʖ ͡°)'); // <-- Here you are editing another users message.
}
});
您要编辑的消息属于该消息的作者,您不能编辑其他用户的消息。
正如您上面所说,您希望它删除消息,所以我将在下面实现它。
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"
}
});
您不需要搜索它,只需在您的消息事件中使用消息的定义即可。
我有我的机器人 运行 一些新代码,但它无法使用 message.edit()
编辑任何消息抛出 DiscordAPIError
任何帮助将不胜感激。
这是我的超级简单机器人的代码
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');
这是每当有人在文本频道中说 'lenny' 时的控制台输出。
(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)
我已经尝试在服务器上赋予管理员角色,但它仍然抛出相同的 DiscordAPIError
错误。
根本无法在 Discord 中编辑来自其他用户的消息,even/especially 使用 API。
作为您要求但无法做到的替代选项,您可以让机器人 post 在有人 post 发送“!lenny”时通过 message.channel.send()
。或者你可以让它更容易,为你的服务器创建一个自定义表情符号,在 :lenny: 的地方显示一个 lenny 的脸,像这样:https://discordemoji.com/emoji/Lenny
引发错误的原因是您试图编辑另一个 用户消息。
client.on('message', message => {
if (message.content === 'lenny') {
message.edit('( ͡° ͜ʖ ͡°)'); // <-- Here you are editing another users message.
}
});
您要编辑的消息属于该消息的作者,您不能编辑其他用户的消息。 正如您上面所说,您希望它删除消息,所以我将在下面实现它。
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"
}
});
您不需要搜索它,只需在您的消息事件中使用消息的定义即可。