Hola comunidad de Stack Overflow, tengo otra pregunta con respecto a discord.js. Quiero enviar un mensaje y agregarle un emoji, del cual luego quiero obtener la lista de usuarios que han reaccionado. Para hacerlo tengo 2 preguntas:
-¿Cómo puedo agregar un emoji? ¿Necesito un detector de eventos separado para un mensaje o puedo hacerlo dentro de mi evento de interacción Crear? pannel.react("👍") que me da el error: 'TypeError: pannel.react is not a function'. ¿Alguien sabe cómo dejar que esto funcione?
-Mi otra pregunta es si hay alguna forma de acceder a la identificación del mensaje desde el mensaje enviado, para verificar quién participó más tarde en otro comando.
Tengo un archivo de índice con mi comando y controladores de eventos. El script es de mi comando "setup.js" en la carpeta "comandos":
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); }); } };Muchas gracias por su ayuda de antemano.
Bien, con la ayuda de @Gh0st pude encontrar una solución:
El problema para enviar un mensaje es que la función .get() necesita la identificación del canal. Lo he accedido a interaction.options.getChannel("destination").id); . No pude agregar una reacción porque mi comando .send no estaba await: const pannel = await channel.send(twitterlink) . La identificación del mensaje es fácil de encontrar usando .id en la variable del mensaje: const pannelid = pannel.id .
El código resultante se puede encontrar a continuación:
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, }); }, };Lo limpie un poco y esto debería funcionar para usted
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, }); }, };