久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Discord JS//嘗試通過對消息做出反應來添加角色

Discord JS // Trying to add role by reacting to the message(Discord JS//嘗試通過對消息做出反應來添加角色)
本文介紹了Discord JS//嘗試通過對消息做出反應來添加角色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

bot.on('messageReactionAdd', async (reaction, user) => {
  // Define the emoji user add       
  let role = message.guild.roles.find(role => role.name === 'Alerts');
  if (message.channel.name !== 'alerts') return message.reply(':x: You must go to the channel #alerts');
  message.member.addRole(role);
});

這是我的 bot.js 的一部分.我希望用戶在某個頻道做出反應并接收角色警報

Thats the part of my bot.js. I want the user to react in a certain channel and receive role Alerts

推薦答案

你還沒有真正說明問題是什么,什么有效,什么無效,但我會在一些能抓住我的地方猛烈抨擊眼睛.

You haven't really stated what the problem is, what works and what doesn't work but I'll take a wild stab at some parts which catch my eye.

對于初學者來說,您正在調用變量 message 的屬性,而在您提供的代碼中,您沒有創建/設置名為 message 的變量.我的猜測是您想要添加了反應的消息.為此,您必須使用 MessageReaction 參數在 messageReactionAdd 事件中作為 reaction 提供.

For starters you are calling properties on the variable message whilst in the code you supplied, you didn't create/set a variable named message. My guess is that you want the message to which a reaction has been added. To do that you have to use the MessageReaction parameter which is supplied in the messageReactionAdd event as reaction.

您可以從那里將 message.<something> 替換為 reaction.message.<something> 在您提供的代碼中的任何位置.

From there you can replace message.<something> with reaction.message.<something> everywhere in the code you supplied.

 

還需要注意的是,您將角色 Alerts 添加到 message.member.這不會像您希望的那樣工作,因為它會將警報角色賦予原始消息的作者.

Something also to note is that you add the role Alerts to message.member. This won't work how you want it to, since it will give the Alerts role to the author of the original message.

(我認為)您想要做的是獲取剛剛對表情符號做出反應的用戶并為他們分配警報角色.您必須先在公會中找到該成員,然后為他們分配警報角色.為此,您必須使用 User 參數并找到正確的 Member 因為您不能將角色添加到 User 對象,但可以添加到 Member 對象.下面是一些希望能讓你走上正軌的代碼.

What (I think) you want to do, is fetch the user who just reacted with the emoji and assign them the Alerts role. You'll have to find the member in the guild first and then assign them the Alerts role. To do this you'll have to use the User parameter and find the correct Member because you can't add a role to a User object but you can to a Member object. Below is some code which should hopefully put you on the right track.

// Fetch and store the guild (the server) in which the message was send.
const guild = reaction.message.guild;

const memberWhoReacted = guild.members.find(member => member.id === user.id);

memberWhoReacted.addRole(role);

這篇關于Discord JS//嘗試通過對消息做出反應來添加角色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 午夜视频在线免费观看 | 午夜影院在线视频 | 成人在线黄色 | 91久久精 | 欧美乱操| 99热在线免费 | 在线观看国产视频 | 久久久久久久久久久久亚洲 | 综合久| 妹子干综合 | 国产精品自拍视频 | 一区二区三区高清 | 一区欧美 | 日韩一级电影免费观看 | 亚洲a级| 成人久久久久 | 亚洲天堂一区 | 亚洲国产一区视频 | 在线观看亚洲专区 | 国产激情视频在线观看 | 亚洲 自拍 另类 欧美 丝袜 | 中文字幕1区2区3区 日韩在线视频免费观看 | 天天干人人 | 午夜小电影 | 能免费看的av | 亚洲一区二区三区在线播放 | 久久久久91| 久夜精品 | 成人午夜精品 | 一区二区国产精品 | 成人午夜激情 | 欧美日韩国产在线观看 | 国产精品极品美女在线观看免费 | 人人看人人草 | 国产成人精品一区二区三 | 午夜av电影院 | 插插宗合网| 亚洲黄色一区二区三区 | 成人性视频在线播放 | 狠狠的干| 热99|