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,9 +164,13 @@ class BanCommand extends Command {
return; return;
} }
// Gets guildMember
const guildMember = guild.members.cache.get(user.id);
if (guildMember !== undefined) {
// Checks if the user is not restricted // Checks if the user is not restricted
if (user.roles.cache.has(IDs.roles.vegan.vegan) if (guildMember.roles.cache.has(IDs.roles.vegan.vegan)
|| user.roles.cache.has(IDs.roles.nonvegan.nonvegan)) { || guildMember.roles.cache.has(IDs.roles.nonvegan.nonvegan)) {
await message.react('❌'); await message.react('❌');
await message.reply({ await message.reply({
content: 'You need to restrict the user first!', content: 'You need to restrict the user first!',
@ -180,13 +184,14 @@ class BanCommand extends Command {
.catch(); .catch();
// Ban the user // Ban the user
await user.ban({ reason }); await guildMember.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;