Skip to content

Instantly share code, notes, and snippets.

@apos37
Created August 12, 2022 21:43
Show Gist options
  • Save apos37/a8233b007de83cdbb50f5a243751a420 to your computer and use it in GitHub Desktop.
Save apos37/a8233b007de83cdbb50f5a243751a420 to your computer and use it in GitHub Desktop.
Pylon Bot Ban User Command
/**
* Ban a user by mention or id
*/
commands.raw('ban', async (message) => {
// Get the current user
var _currentUser = message.member;
// Check if the current user has the admin role if trying to change someone else's nickname
if (!_currentUser.roles.includes(ADMIN_ROLE_ID)) {
return message.reply(
`Hey buddy! You don't have the authority to ban someone. Please ask an <@${ADMIN_ROLE_ID}>.`
);
}
// Get the user id
const _mentions = message.mentions;
const _msg = message.content.replace('!ban', '').replaceAll(' ', '');
var _userID = '';
if (_mentions[0]) {
_userID = _mentions[0].id;
} else if (_msg != '') {
_userID = _msg;
}
// Get the guild
const channel = await discord.getGuildTextChannel(WELCOME_CHANNEL_ID);
if (!channel) {
return;
}
const guild = await discord.getGuild(channel.guildId);
if (!guild) {
return;
}
// Ban them
if (_userID != '') {
await guild.createBan(_userID);
}
// Message
var msg = '';
if (_userID != '') {
msg = '<@' + _userID + '> has been banned.';
} else {
msg = 'Please specify a user.';
}
if (msg != '') {
message.reply(msg);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment