1 |
import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js'; |
import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, Permissions, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
10 |
import ms from 'ms'; |
import ms from 'ms'; |
11 |
import { unmute } from './UnmuteCommand'; |
import { unmute } from './UnmuteCommand'; |
12 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
13 |
|
import { hasPermission, shouldNotModerate } from '../../utils/util'; |
14 |
|
|
15 |
export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) { |
export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) { |
16 |
try { |
try { |
57 |
user_id: user.id, |
user_id: user.id, |
58 |
roles: roles.map(role => role.id), |
roles: roles.map(role => role.id), |
59 |
guild_id: msg.guild!.id, |
guild_id: msg.guild!.id, |
60 |
|
createdAt: new Date() |
61 |
}); |
}); |
62 |
} |
} |
63 |
|
|
77 |
}); |
}); |
78 |
|
|
79 |
await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User, hard); |
await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User, hard); |
80 |
await user.send({ |
|
81 |
embeds: [ |
try { |
82 |
new MessageEmbed() |
await user.send({ |
83 |
.setAuthor({ |
embeds: [ |
84 |
iconURL: <string> msg.guild!.iconURL(), |
new MessageEmbed() |
85 |
name: `\tYou have been muted in ${msg.guild!.name}` |
.setAuthor({ |
86 |
}) |
iconURL: <string> msg.guild!.iconURL(), |
87 |
.addField("Reason", reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason) |
name: `\tYou have been muted in ${msg.guild!.name}` |
88 |
] |
}) |
89 |
}); |
.addField("Reason", reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason) |
90 |
|
] |
91 |
|
}); |
92 |
|
} |
93 |
|
catch (e) { |
94 |
|
console.log(e); |
95 |
|
} |
96 |
} |
} |
97 |
catch (e) { |
catch (e) { |
98 |
console.log(e); |
console.log(e); |
120 |
|
|
121 |
export default class MuteCommand extends BaseCommand { |
export default class MuteCommand extends BaseCommand { |
122 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
123 |
|
permissions = [Permissions.FLAGS.MODERATE_MEMBERS]; |
124 |
|
|
125 |
constructor() { |
constructor() { |
126 |
super('mute', 'moderation', []); |
super('mute', 'moderation', []); |
242 |
dateTime = Date.now() + timeInterval; |
dateTime = Date.now() + timeInterval; |
243 |
} |
} |
244 |
|
|
245 |
|
if (!(await hasPermission(client, user, msg, null, "You don't have permission to mute this user."))) { |
246 |
|
return; |
247 |
|
} |
248 |
|
|
249 |
|
if (shouldNotModerate(client, user)) { |
250 |
|
await msg.reply({ |
251 |
|
embeds: [ |
252 |
|
{ |
253 |
|
description: "This user cannot be muted." |
254 |
|
} |
255 |
|
] |
256 |
|
}); |
257 |
|
|
258 |
|
return; |
259 |
|
} |
260 |
|
|
261 |
await mute(client, dateTime, user, msg, timeInterval, reason, hard); |
await mute(client, dateTime, user, msg, timeInterval, reason, hard); |
262 |
|
|
263 |
const fields = [ |
const fields = [ |
293 |
] |
] |
294 |
}); |
}); |
295 |
} |
} |
|
} |
|
296 |
|
} |