最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cant edit messages with discord bot (UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message autho

programmeradmin1浏览0评论

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.

Share Improve this question edited Jun 18, 2019 at 20:48 JROS asked May 21, 2019 at 20:06 JROSJROS 711 gold badge2 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

The 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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论