parent
cbd0bc3c42
commit
8a8b7c6bab
@ -0,0 +1,33 @@ |
|||||||
|
const Discord = require('discord.js'); |
||||||
|
const GuildData = require('../models/guild'); |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
name: "autorole", |
||||||
|
aliases: ['joinrole', 'jr'], |
||||||
|
help: new Discord.MessageEmbed() |
||||||
|
.setTitle("Help -> Auto Role/Join Role") |
||||||
|
.setDescription("Set a role to be automatically added to users when they join the server.") |
||||||
|
.addField("Syntax", "`autorole <set|clear|view>`") |
||||||
|
.addField('Notice', "This command can only be used by server staff members and admins."), |
||||||
|
async execute(message, msg, args, cmd, prefix, mention, client) { |
||||||
|
if (!message.guild) {return message.reply("This command is only available in servers.");} |
||||||
|
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}autorole <set|clear|view>\``);} |
||||||
|
let tg = await GuildData.findOne({gid: message.guild.id}) ? await GuildData.findOne({gid: message.guild.id}) : new GuildData({gid: message.guild.id}); |
||||||
|
if (['v', 'view', 'check'].includes(args[0])) {return message.channel.send(tg.joinrole.length && message.guild.roles.cache.has(tg.joinrole) ? `I am currently adding \`${message.guild.roles.cache.get(tg.joinrole).name}\` to new members.` : "At the moment, I'm not adding a role to new members.");} |
||||||
|
if ((!tg.staffrole.length || !message.member.roles.cache.has(tg.staffrole)) && !message.member.permissions.has("ADMINISTRATOR")) {return message.reply("You don't have the permissions to edit this setting.");} |
||||||
|
if (['s', 'set', 'c', 'clear'].includes(args[0])) { |
||||||
|
let role = message.mentions.roles.first() ? message.mentions.roles.first().id : args[1] && message.guild.roles.cache.has(args[1]) ? args[1] : ['c', 'clear'].includes(args[0]) ? '' : null; |
||||||
|
if (role === null) {return message.reply("That doesn't seem to be a role!");} |
||||||
|
tg.joinrole = role; |
||||||
|
tg.save(); |
||||||
|
return message.channel.send(new Discord.MessageEmbed() |
||||||
|
.setTitle("Join Role Updated") |
||||||
|
.setThumbnail(message.author.avatarURL({size: 2048})) |
||||||
|
.setDescription(`Role: ${tg.joinrole.length ? `<@&${tg.joinrole}>` : "None"}`) |
||||||
|
.setColor("c375f0") |
||||||
|
.setFooter('Natsuki', client.user.avatarURL()) |
||||||
|
.setTimestamp() |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,8 @@ |
|||||||
|
const GuildData = require('../models/guild'); |
||||||
|
|
||||||
|
module.exports = async (client, member) => { |
||||||
|
let tg = await GuildData.findOne({gid: member.guild.id}); |
||||||
|
if (tg && tg.joinrole.length && member.guild.roles.cache.has(tg.joinrole)) { |
||||||
|
if (member.guild.members.cache.get(client.user.id).permissions.has("MANAGE_ROLES")) {member.roles.add(tg.joinrole);} |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue