[英]Discord js check reaction user role
I am trying to close a ticket by reacting to a button.我正在尝试通过对按钮做出反应来关闭票证。 But reaction must be given by "support" role.
但反应必须由“支持”角色给出。 I couldnt do it.
我做不到。 reaction.message.member.roles.has is not helping me at this point.
在这一点上,reaction.message.member.roles.has 对我没有帮助。 Here is my code;
这是我的代码;
client.on("messageReactionAdd", (reaction, user) => {
if(reaction.message.member.roles.has('ROLE')) {
let id = user.id.toString().substr(0, 4) + user.discriminator;
let chan = `ticket-${id}`;
const supchan = reaction.message.guild.channels.find(
(channel) => channel.name === chan
);
const chan_id = supchan ? supchan.id : null;
if (
reaction.emoji.name === "🔒" &&
!user.bot &&
user.id != "ID"
) {
reaction.removeAll();
const channel = client.channels.find("name", chan);
const delMsg = new Discord.RichEmbed()
.setColor("#E74C3C")
.setDescription(`:boom: Ticket will be deleted in 5 seconds.`);
channel.send(delMsg).then(() => {
var counter = 0;
const intervalObj = setInterval(() => {
counter++;
if (counter == 5) {
const message = reaction.message;
message.delete();
Thanks for helps !感谢您的帮助!
All of this wrapped inside the messageReactionAdd
event所有这些都包含在
messageReactionAdd
事件中
// Replace "message_id" with the proper message id
// Checks if it's the correct message
if (reaction.message.id == "message_id") {
// Check if author of ticket message is from the same user who reacted
if (reaction.message.author == user) {
// Check correct emoji
if (reaction.emoji.name == "🔒") {
// Code to close ticket
}
}
}
EDIT: Again, this would be wrapped inside the messageReactionAdd
event:编辑:同样,这将被包装在
messageReactionAdd
事件中:
// Try to get the ticket message
// If there's none then the user was never opened a ticket so we simply return the code
const ticketMessage = client.tickets.get(user);
if (!ticketMessage) return;
// Checks if it's the correct message
if (reaction.message.id == ticketMessage.id) {
// Check correct emoji
if (reaction.emoji.name == "🔒") {
// Code to close ticket
}
}
I removed the code that check for the reaction message author because getting ticketMessage
already handles that.我删除了检查反应消息作者的代码,因为获取
ticketMessage
已经处理了。 Do note that this means you can make sure a user can only open one ticket.请注意,这意味着您可以确保用户只能打开一张票。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.