1
votes

I try to change an already send Embed per command. I got an command that makes an embed and sends it in an user defined Channel (selchannel). But when i try to edit the Embed I get:

DiscordAPIError: Cannot edit a message authored by another user

But the Message was send by the bot so why does it say this?

How i send the original Embed:

// constructing Embed...
let messageEmbed = await client.channels.cache.get(selchannel).send({embed: EmbedMessage})
module.exports = {
        messageEmbed,
        EmbedMessage
    }

How i try to edit it:

module.exports = {
name: 'edit-embed',
description: 'Edits send Embed',
async execute(message, args) {
    const Discord = require('discord.js');
    const { messageEmbed } = require('./embed');
    const { EmbedMessage } = require('./embed');
    const { prefix } = require('/home/ubuntu/discord-bot/main.js');
    const sender = `${message.author.tag}`;
    const InputSlice = message.content.slice(prefix.length).trim().split(' ');
    const sEmbed = args.shift().toLowerCase();
    const newEmbed = new Discord.MessageEmbed()

    .setColor('#8022FF')
    .setTitle('.........:')
    .addFields(
        {name: '\u200B', value: '\u200B'},
        {name: '........: ', value: ' ............' }, 
        {name: '\u200B', value: '\u200B'}
    )
    .setImage('...........')
    .setFooter(`............  -(${sender})-`);  

    message.edit(sEmbed).then(newEmbed);
}

}

What am i doin' wrong?

1
message.edit tries to edit the message with the command and that's coming from a user, not the bot. Shouldn't it be messageEmbed.edit(newEmbed)? - Zsolt Meszaros
Well now it says "TypeError: Cannot read property 'edit' of undefined"... - SoldØut

1 Answers

0
votes

You should probably assign the embed to a variable as a message object, and then you can use <yourvariable (the embed sent by the bot)>.edit(your other variable)

In other words, you need to add another variable to the execute() function (which would be the message as a message object)

if you want, here would be an example of how you could do it (I think)

// constructing Embed...
let messageEmbed = await client.channels.cache.get(selchannel).send({embed: EmbedMessage})
module.exports = {
        messageEmbed,
        EmbedMessage
    }

module.exports = {
name: 'edit-embed',
description: 'Edits send Embed',
async execute(message, args, botEmbed) { //add botEmbed (which is a message object)
    const Discord = require('discord.js');
    const { messageEmbed } = require('./embed');
    const { EmbedMessage } = require('./embed');
    const { prefix } = require('/home/ubuntu/discord-bot/main.js');
    const sender = `${message.author.tag}`;
    const InputSlice = message.content.slice(prefix.length).trim().split(' ');
    const sEmbed = args.shift().toLowerCase();
    const newEmbed = new Discord.MessageEmbed()

    .setColor('#8022FF')
    .setTitle('.........:')
    .addFields(
        {name: '\u200B', value: '\u200B'},
        {name: '........: ', value: ' ............' }, 
        {name: '\u200B', value: '\u200B'}
    )
    .setImage('...........')
    .setFooter(`............  -(${sender})-`);  

    botEmbed.edit(sEmbed).then(newEmbed); //change message to botEmbed
}

and then when you call the edit function, just pass in another property, which would be the message object of the embed that you sent

I hope this works! (haven't tested it)