亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.JS 反應

Discord.JS 反應

慕姐4208626 2023-07-06 11:00:08
我正在開發一個票證機器人,我希望它能夠讓您對消息做出反應以創建票證。我可以發送消息,但當我使用時,bot.on('messageReactionAdd')如果我的機器人重新啟動,它不會檢測到已添加反應,除非您發送新消息并對自機器人上線以來創建的消息做出反應。這對我來說是一個問題,我知道它是可以解決的。我嘗試過谷歌搜索,但無法解決問題。這里有人可以幫助我嗎?
查看完整描述

2 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

從 Discord.js v12 開始,您可以在機器人上啟用部分功能,允許其發送未獲取消息的事件,但代價是您必須在處理程序開始時自己獲取消息:

const Discord = require('discord.js');

// Make sure you instantiate the client with the correct settings

const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });

client.on('messageReactionAdd', async (reaction, user) => {

? ? // When we receive a reaction we check if the reaction is partial or not

? ? if (reaction.partial) {

? ? ? ? // If the message this reaction belongs to was removed the fetching might result in an API error, which we need to handle

? ? ? ? try {

? ? ? ? ? ? await reaction.fetch();

? ? ? ? } catch (error) {

? ? ? ? ? ? console.error('Something went wrong when fetching the message: ', error);

? ? ? ? ? ? // Return as `reaction.message.author` may be undefined/null

? ? ? ? ? ? return;

? ? ? ? }

? ? }

? ? // Now the message has been cached and is fully available

? ? console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);

? ? // The reaction is now also fully available and the properties will be reflected accurately:

? ? console.log(`${reaction.count} user(s) have given the same reaction to this message!`);

});


查看完整回答
反對 回復 2023-07-06
?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

您可以根據需要使用它,但這里有一個示例:


message.channel.send("React test!").then(messageReaction => {

    messageReaction.react("?");

    messageReaction.react("?");

  });


查看完整回答
反對 回復 2023-07-06
  • 2 回答
  • 0 關注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號