我正在尝试为我们的FiveM服务器创建一个处理不和谐角色的不和谐社区机器人。 我希望机器人限制该ROLECHANNEL,因此只能发布角色命令。我想删除其他垃圾,以便频道保持干净。
该命令正在运行并且已分配角色,但该漫游器还会触发message.reply('Wrong role, type ' + prefix +'roles');
为什么?
client.on('message', message => {
if (message.channel.id === ROLECHANNEL) {
if (message.author.bot) return;
if (!message.content.includes("fivem", "ark", "arma3", "roles", "stream",)) {
message.delete([1]);
message.reply('Wrong role, type ' + prefix +'roles');
}
if(message.content.startsWith(prefix + "fivem")){
message.delete([1]);
let fivemrole = message.member.guild.roles.find("name", "fivem");
message.member.addRole(fivemrole);
message.channel.send('Gives ' + message.author + ' fivem role...');
}
if(message.content.startsWith(prefix + "arma3")){
message.delete([1])
let armarole = message.member.guild.roles.find("name", "Arma3");
message.member.addRole(armarole);
message.channel.send('Gives ' + message.author + ' Arma3 role...');
}
if(message.content.startsWith(prefix + "ark")){
message.delete([1]);
let arkrole = message.member.guild.roles.find("name", "Ark");
message.member.addRole(arkrole);
message.channel.send('Gives ' + message.author + ' Ark role...');
}
if(message.content.startsWith(prefix + "stream")){
message.delete([1]);
let streamerrole = message.member.guild.roles.find("name", "Streamer");
message.member.addRole(streamerrole);
message.channel.send('Gives ' + message.author + ' Streamer role...');
}
if (message.content.startsWith(prefix + "roles")) {
message.delete([1]);
message.channel.send('Help: ' + message.author + ' roles are. ' + roles);
}
};
答案 0 :(得分:0)
您在此部分遇到的问题!message.content.includes("fivem", "ark", "arma3", "roles", "stream",)
由于消息仅包含监听第一拳头参数“ fivem”,因此您需要在代码中添加or
块
V2
第一拳变种:
if(!message.content.includes("fivem") && !message.content.includes("ark") && !message.content.includes("arma3"))
或者您可以设置允许的变量数组并检查
let allowedCommands = ["fivem", "ark", "arma3", "roles", "stream"]
if (!allowedCommands.find(command => message.content.indexOf(command) !== -1)) {
message.delete([1]);
message.reply('Wrong role, type ' + prefix +'roles');
}