118 lines
4.0 KiB
JavaScript
118 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
const { time } = require("discord.js");
|
|
|
|
|
|
module.exports = {
|
|
name: 'timeout',
|
|
description: `timeout a user`,
|
|
aliases: ['mute'],
|
|
usage: 'timeout <user> <duration>',
|
|
|
|
async execute(client, message, args) {
|
|
var embed;
|
|
|
|
if (!message.member.permissions.has('ModerateMembers')) {
|
|
await message.reply({
|
|
content: null, embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
description: '<:no:1481811955592466492> you do not have permissions to run this command!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date(),
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (!message.mentions.members.size) {
|
|
await message.reply({
|
|
content: null, embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
description: '<:no:1481811955592466492> please specify a user to timeout!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date(),
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
const member = message.mentions.members.first();
|
|
|
|
const durationStr = args[1];
|
|
const durationMap = { s: 1000, m: 60000, h: 3600000, d: 86400000, w: 604800000 };
|
|
const match = durationStr?.match(/^(\d+)([smhdw])$/);
|
|
|
|
if (!match || !durationMap[match[2]]) {
|
|
return message.reply({
|
|
content: null, embeds: [{
|
|
color: 0x8aa2b3,
|
|
author: {
|
|
name: message.author.username,
|
|
icon_url: message.author.displayAvatarURL(),
|
|
},
|
|
description: '<:no:1481811955592466492> please specify a valid duration (e.g., 1s, 1m, 1d, 1w)!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date(),
|
|
}]
|
|
});
|
|
}
|
|
|
|
const duration = parseInt(match[1]) * durationMap[match[2]];
|
|
|
|
if (!duration) {
|
|
await message.reply({
|
|
content: null, embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
description: '<:no:1481811955592466492> please specify a valid duration for the timeout!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date(),
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await member.timeout(duration);
|
|
embed = {
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
description: `<:check:1481811973447356496> ${member} has been timed out for ${durationStr}!`,
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date(),
|
|
};
|
|
} catch (error) {
|
|
console.error(error);
|
|
embed = {
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
description: '<:no:1481811955592466492> an error occurred while trying to timeout the user!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date(),
|
|
};
|
|
}
|
|
|
|
await message.reply({ content: null, embeds: [embed] });
|
|
},
|
|
};
|