feat(arabot): add ability to ban when user is not in server

This commit is contained in:
smyalygames 2022-10-28 02:47:59 +01:00
parent 722f0a53f1
commit 556038ee80

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message, TextChannel } from 'discord.js'; import type { User, Message, TextChannel } from 'discord.js';
import IDs from '../../utils/ids'; import IDs from '../../utils/ids';
import { addBan } from '../../utils/database/ban'; import { addBan } from '../../utils/database/ban';
@ -68,7 +68,7 @@ class BanCommand extends Command {
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null // Gets guildMember
const guildMember = guild.members.cache.get(user.id); const guildMember = guild.members.cache.get(user.id);
// Checks if guildMember is null // Checks if guildMember is null
@ -126,9 +126,9 @@ class BanCommand extends Command {
// Non Application Command method of banning a user // Non Application Command method of banning a user
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
@ -164,29 +164,34 @@ class BanCommand extends Command {
return; return;
} }
// Checks if the user is not restricted // Gets guildMember
if (user.roles.cache.has(IDs.roles.vegan.vegan) const guildMember = guild.members.cache.get(user.id);
|| user.roles.cache.has(IDs.roles.nonvegan.nonvegan)) {
await message.react('❌'); if (guildMember !== undefined) {
await message.reply({ // Checks if the user is not restricted
content: 'You need to restrict the user first!', if (guildMember.roles.cache.has(IDs.roles.vegan.vegan)
}); || guildMember.roles.cache.has(IDs.roles.nonvegan.nonvegan)) {
return; await message.react('❌');
await message.reply({
content: 'You need to restrict the user first!',
});
return;
}
// Send DM for reason of ban
await user.send(`You have been banned from ARA for: ${reason}`
+ '\n\nhttps://vbcamp.org/ARA')
.catch();
// Ban the user
await guildMember.ban({ reason });
} }
// Send DM for reason of ban
await user.send(`You have been banned from ARA for: ${reason}`
+ '\n\nhttps://vbcamp.org/ARA')
.catch();
// Ban the user
await user.ban({ reason });
await message.react('✅');
// Add ban to database // Add ban to database
await addBan(user.id, mod.id, reason); await addBan(user.id, mod.id, reason);
await message.react('✅');
// Log the ban // Log the ban
let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as TextChannel | undefined; let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as TextChannel | undefined;