当有人加入我的不和谐服务器时,我需要一个AutoRole命令discord.js,他将获得不和谐成员的角色。
我尝试了一些代码,但是没有用。
const discord = require("discord.js");
const config = require('../config.json');
module.exports.run = async (bot, message, args) => {
let target = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
let reason = args.slice(1).join(' ');
let logs = message.guild.channels.find('name', config.logsChannel);
if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply('you do not have permissions to use this command!s');
if (!target) return message.reply('please specify a member to ban!');
if (!reason) return message.reply('please specify a reason for this ban!');
if (!logs) return message.reply(`please create a channel called ${config.logsChannel} to log the bans!`);
let embed = new discord.RichEmbed()
.setColor('RANDOM')
.setThumbnail(target.user.avatarURL)
.addField('Banned Member', `${target.user.username} with an ID: ${target.user.id}`)
.addField('Banned By', `${message.author.username} with an ID: ${message.author.id}`)
.addField('Banned Time', message.createdAt)
.addField('Banned At', message.channel)
.addField('Banned Reason', reason)
.setFooter('Banned user information', target.user.displayAvatarURL);
message.channel.send(`${target.user.username} was banned by ${message.author} for ${reason}`);
target.ban(reason);
logs.send(embed);
};
module.exports.help = {
name: 'ban'
};
加入后,他们将获得“不和谐会员”角色。
答案 0 :(得分:2)
您可以使用guildMemberAdd
事件对新用户执行操作。
client.on("guildMemberAdd", (member) => {
member.addRole('ROLE ID HERE')
});