简体   繁体   中英

How to fetch a message by its ID then react to it

I am trying to get the message ID of a newly created message like this. What would I use instead of message.channel.fetch(id) to fetch a message id? I can't seem to find it:

async function messageSend() {
  let messageId = await message.channel.send('Test');
  let { id } = messageId;
  const emojiCheck = '✅';
  const emojiNo = '❌';
  const nebzlaID = '569860318608490496';
  message.channel.messages.fetch(id).react(emojiCheck);
  message.channel.messages.fetch(id).react(emojiNo);

  const suggestionDM = new Discord.MessageEmbed()
    .setColor('#fffff')
    .setTitle('There is a new suggestion in abc!').setDescription(`
        User: ${suggestUser}
        \n\nSuggestion: ${suggestion}

        `);
  // ...

channel.messages.fetch() returns a promise, it means you need to resolve it first to get the message you can react to. You can use await :

async function messageSend() {
  const { id } = await message.channel.send('Test');
  const emojiCheck = '✅';
  const emojiNo = '❌';
  const nebzlaID = '569860318608490496';

  const messageToReact = await message.channel.messages.fetch(id);

  messageToReact.react(emojiCheck);
  messageToReact.react(emojiNo);

  // ...

Although it's not necessary to fetch it again, you could simply react to the returned message:

async function messageSend() {
  const sentMessage = await message.channel.send('Test');
  const emojiCheck = '✅';
  const emojiNo = '❌';
  const nebzlaID = '569860318608490496';

  sendMessage.react(emojiCheck);
  sendMessage.react(emojiNo);

  // ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM