Added timeout command

This commit is contained in:
2023-11-24 23:51:40 +01:00
parent e6fc6296c4
commit 97d3068d28
4 changed files with 143 additions and 3 deletions

3
package-lock.json generated
View File

@@ -13,7 +13,8 @@
"discord.js": "^14.8.0",
"dotenv": "^16.0.3",
"log-beautify": "^1.2.0",
"mongoose": "^7.0.1"
"mongoose": "^7.0.1",
"ms": "^2.1.3"
}
},
"node_modules/@discordjs/builders": {

View File

@@ -16,6 +16,7 @@
"discord.js": "^14.8.0",
"dotenv": "^16.0.3",
"log-beautify": "^1.2.0",
"mongoose": "^7.0.1"
"mongoose": "^7.0.1",
"ms": "^2.1.3"
}
}

View File

@@ -7,7 +7,6 @@ module.exports = {
name: "check",
description: "Check a player's stats.",
type: "slash",
dev: true,
data: new SlashCommandBuilder()
.setName("check")

139
src/commands/timeout.js Normal file
View File

@@ -0,0 +1,139 @@
const { SlashCommandBuilder, PermissionFlagsBits, userMention } = require("discord.js")
const { color } = require("../../config/options.json")
const ms = require("ms")
module.exports = {
name: "timeout",
description: "Times out a memeber",
type: "slash",
dev: true,
data: new SlashCommandBuilder()
.setName("timeout")
.setDescription("Times out a memeber")
.addUserOption(option =>
option
.setName("user")
.setDescription("The user to timeout")
.setRequired(true))
.addStringOption(option =>
option
.setName("time")
.setDescription("The time to timeout the user for")
.setRequired(true))
.addStringOption(option =>
option
.setName("reason")
.setDescription("The reason for the timeout"))
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setDMPermission(false),
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
async execute(interaction) {
await interaction.deferReply()
const target1 = interaction.options.getUser("user")
const target = interaction.guild.members.cache.get(target1.id)
const timeString = interaction.options.getString("time")
const reason = interaction.options.getString("reason") || "No reason provided"
const time = ms(timeString)
const embedColor = Number(color.replace("#", "0x"))
if (target.bot) {
interaction.deferReply({
embeds: [{
description: "You cannot timeout a bot.",
color: embedColor,
}]
})
return
}
if (target.id == interaction.guild.ownerId) {
await interaction.deferReply({
embeds: [{
description: "You cannot timeout the server owner.",
color: embedColor,
}]
})
return
}
if (interaction.guild.members.me.roles.highest.position <= target.roles.highest.position) {
interaction.deferReply({
embeds: [{
description: "I cannot timeout this user because their role is higher than mine.",
color: embedColor,
}]
})
return
}
if (interaction.member.roles.highest.position <= target.roles.highest.position) {
await interaction.deferReply({
embeds: [{
description: "You cannot timeout this user because their role is higher than yours.",
color: embedColor,
}]
})
return
}
if (target.id == interaction.user.id) {
interaction.deferReply({
embeds: [{
description: "You cannot timeout yourself.",
color: embedColor,
}]
})
return
}
if (target.isCommunicationDisabled()) {
if (time === 0) {
await target.timeout(null, reason)
await interaction.editReply({
embeds: [{
description: "Removed timeout of " + userMention(target.id) + " for " + reason,
color: embedColor,
footer: {
text: "ID: " + target.id,
iconURL: target.avatarURL()
},
timestamp: new Date()
}]
})
return
}
await target.timeout(time, reason)
await interaction.editReply({
embeds: [{
description: "Updated timeout of " + userMention(target.id) + " to " + timeString + " for " + reason,
color: embedColor,
footer: {
text: "ID: " + target.id,
iconURL: target.avatarURL()
},
timestamp: new Date()
}]
})
return
}
await target.timeout(time, reason)
await interaction.editReply({
embeds: [{
description: "Timed out " + userMention(target.id) + " for " + timeString + " for " + reason,
color: embedColor,
footer: {
text: "ID: " + target.id,
iconURL: target.avatarURL()
},
timestamp: new Date()
}]
})
}
}