'Discord.js Adding Emojis to a send message and grab the message id

Hey Stack Overflow Community, I have another question in regard to discord.js.I want to send a message and add an emoji to it, from which I later want to get the list of users who have reacted. In order to do so I have 2 questions:

-How can I add an emoji? Do I need a separate event listener for a message or can I do it within my interactionCreate event? I have tried pannel.react("👍") which gives me the error: 'TypeError: pannel.react is not a function'. Does anyone know how to let this work?

-My other question is if there is a way to access the message id from the send message, in order to check who has participated later on in another command?

I have an index file with my command and event handlers. The script is from my "setup.js" command in the "commands" folder:

const { SlashCommandBuilder } = require("@discordjs/builders");
const Discord = require("discord.js");

module.exports = {
    data: new SlashCommandBuilder()
        .setName("setup")
        .setDescription("Setup Tweet to be rewarded")
        .addChannelOption(option =>
            option
            .setName('destination')
            .setDescription('Select a channel for the reward pannel')
            .setRequired(true)
            )
        .addStringOption(option =>
            option
                .setName("twitterlink")
                .setDescription("Enter the Twitter Link")
                .setRequired(false)
                ),

    async execute(interaction) {

        interaction.reply({
            content: "Pannel send",
            ephemeral: true
        }).then( function () {

        const channel = interaction.options.getChannel("destination");
        const channelid = channel.id;
        const twitterlink = interaction.options.getString("twitterlink");

       const pannel = interaction.guild.channels.cache.get(channelid).send(twitterlink);
    });
    }
};

Thank you very much for your assistance in advance.



Solution 1:[1]

Okay with the help from @Gh0st I was able to find a solution:

The problem in order to send a message is that the .get() function need the channel id. I have accessd it to interaction.options.getChannel("destination").id);. I couldnt add a reaction because my .send command was not await: const pannel = await channel.send(twitterlink). The message id is easiy to find by using .id on the variable of the message: const pannelid = pannel.id.

The resulting code can be found below:

const { SlashCommandBuilder } = require("@discordjs/builders");
const Discord = require("discord.js");




module.exports = {
    data: new SlashCommandBuilder()
        .setName("setup")
        .setDescription("Setup Tweet to be rewarded")
        .addChannelOption(option =>
            option
            .setName('destination')
            .setDescription('Select a channel for the reward pannel')
            .setRequired(true)
            )
        .addStringOption(option =>
            option
                .setName("twitterlink")
                .setDescription("Enter the Twitter Link")
                .setRequired(false)
                ),

                async execute(interaction) { // Fixed below here and simplified it
                    const channel = interaction.guild.channels.cache.get(interaction.options.getChannel("destination").id);
                    const twitterlink = interaction.options.getString("twitterlink");
            
                    const pannel = await channel.send(twitterlink)
                    pannel.react('?');
                    const pannelid = pannel.id
            
                    return interaction.reply({
                        content: "Pannel send",
                        ephemeral: true,
                    });
                },
            };

Solution 2:[2]

Cleaned it up a bit and this should work for you

const {
    SlashCommandBuilder,
} = require("@discordjs/builders");
const Discord = require("discord.js");

module.exports = {
    data: new SlashCommandBuilder()
        .setName("setup")
        .setDescription("Setup Tweet to be rewarded")
        .addChannelOption(option =>
            option
                .setName('destination')
                .setDescription('Select a channel for the reward pannel')
                .setRequired(true),
        )
        .addStringOption(option =>
            option
                .setName("twitterlink")
                .setDescription("Enter the Twitter Link")
                .setRequired(false),
        ),
    async execute(interaction) { // Fixed below here and simplified it
        const channel = interaction.guild.channels.cache.get(interaction.options.getChannel("destination").id);
        const twitterlink = interaction.options.getString("twitterlink");

        channel.send(twitterlink).then(msg => {
            msg.react('?'),
        });

        return interaction.reply({
            content: "Pannel send",
            ephemeral: true,
        });
    },
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 N0rmal
Solution 2