这是命令代码,机器人在对某个表情符号做出反应后会给你一个角色,但在你重新启动后它就停止监听旧消息,迫使我创建一个新消息:
module.exports = {
name: "reactionrole",
description: "Pone un mensaje con roles por reacción",
async execute(message, args, Discord, client) {
message.delete();
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.reply("Negative! You don´t have permissions to do that.")
const channel = "805195024173367327";
const MemberRole = message.guild.roles.cache.find(role => role.name === "Member");
const EuropeRole = message.guild.roles.cache.find(role => role.name === "Europe");
const NARole = message.guild.roles.cache.find(role => role.name === "NA");
const LATAMRole = message.guild.roles.cache.find(role => role.name === "LATAM");
const EuropeEmoji = "??";
const NAEmoji = "??";
const LATAMEmoji = "?";
let embed = new Discord.MessageEmbed()
.setColor("#FF0000")
.setTitle("Welcome to BOT Wally's server")
.setDescription(`Report in. Hello, I´m BOT Wally, welcome to my server. Please, select your region down below to become a member:\n\n`
+ `${EuropeEmoji} for EUROPE\n`
+ `${NAEmoji} for NA\n`
+ `${LATAMEmoji} for LATAM\n`
+ `\nEnjoy your stay!`);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(EuropeEmoji);
messageEmbed.react(NAEmoji);
messageEmbed.react(LATAMEmoji);
client.on("messageReactionAdd", async (reaction, user) => {
if (reaction.message.channel.id == channel) {
if(user.partial) await user.fetch();
if(reaction.partial) await reaction.fetch();
if(reaction.message.partial) await reaction.message.fetch();
if (reaction.emoji.name === EuropeEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(MemberRole);
await reaction.message.guild.members.cache.get(user.id).roles.add(EuropeRole);
user.send("Hold this position! Gratz, now you're a memeber of my server. You have selected EUROPE, if you wanna change **your region** contact us via support chat.\n-If you wanna know how I work, just **tag me** in the server.\n-If you want further support please head over to **support chat**.\n-Don't forget to read the **rules** channel.");
}
if (reaction.emoji.name === NAEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(MemberRole);
await reaction.message.guild.members.cache.get(user.id).roles.add(NARole);
user.send("Hold this position! Gratz, now you're a memeber of my server. You have selected NA, if you wanna change **your region** contact us via support chat.\n-If you wanna know how I work, just **tag me** in the server.\n-If you want further support please head over to **support chat**.\n-Don't forget to read the **rules** channel.");
}
if (reaction.emoji.name === LATAMEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(MemberRole);
await reaction.message.guild.members.cache.get(user.id).roles.add(LATAMRole);
user.send("Hold this position! Gratz, now you're a memeber of my server. You have selected LATAM, if you wanna change **your region** contact us via support chat.\n-If you wanna know how I work, just **tag me** in the server.\n-If you want further support please head over to **support chat**.\n-Don't forget to read the **rules** channel.");
}
} else {
return;
}
});
client.on("messageReactionRemove", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === EuropeEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(EuropeRole);
}
if (reaction.emoji.name === NAEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(NARole);
}
if (reaction.emoji.name === LATAMEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(LATAMRole);
}
} else {
return;
}
});
}
}
它运行良好,直到您重新启动,然后停止侦听旧消息。我有另一个命令,它在我的索引中的作用几乎相同,它确实可以处理旧消息。代码:
client.on("messageReactionAdd", async (reaction, user)=> {
if(user.bot) return;
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
if(!ticketid) return;
if(reaction.message.id == ticketid && reaction.emoji.name == "?"){
reaction.users.remove(user);
reaction.message.guild.channels.create(`ticket-${user.username}`, {
permissionOverwrites: [
{
id: user.id,
allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
},
{
id: reaction.message.guild.roles.everyone,
deny: ["VIEW_CHANNEL"]
}
],
type: "text", parent: "805191968786612264"
}).then(async channel => {
channel.send(`<@${user.id}>`, new Discord.MessageEmbed().setTitle("Welcome to your support ticket").setDescription("Please, write your inquiry in this channel and we'll reply ASAP.").setColor("#FF0000"))
})
}
});