This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10c806a
commit 90ab674
Showing
3 changed files
with
197 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,174 +1,182 @@ | ||
const { PermissionFlagsBits } = require('discord.js') | ||
const { EmbedBuilder, SlashCommandBuilder } = require('@discordjs/builders') | ||
const ms = require('ms') | ||
const { Color } = require('discord-image-generation') | ||
const { PermissionFlagsBits } = require("discord.js"); | ||
const { EmbedBuilder, SlashCommandBuilder } = require("@discordjs/builders"); | ||
const ms = require("ms"); | ||
// const { Color } = require('discord-image-generation') | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('timeout') | ||
.setName("timeout") | ||
.setDMPermission(false) | ||
.setDescription('Timeout a user') | ||
.setDescription("Timeout a user") | ||
.addUserOption((option) => | ||
option | ||
.setName('user') | ||
.setDescription('The user you want to timeout') | ||
.setRequired(true) | ||
.setName("user") | ||
.setDescription("The user you want to timeout") | ||
.setRequired(true), | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName('duration') | ||
.setDescription('Duration of the timeout') | ||
.setRequired(true) | ||
.setName("duration") | ||
.setDescription("Duration of the timeout") | ||
.setRequired(true), | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName('reason') | ||
.setDescription('Reason for the timeout') | ||
.setRequired(false) | ||
.setName("reason") | ||
.setDescription("Reason for the timeout") | ||
.setRequired(false), | ||
) | ||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers), | ||
|
||
async execute(interaction) { | ||
try { | ||
await interaction.deferReply() | ||
await interaction.deferReply(); | ||
|
||
const targetUserID = interaction.options.getUser('user') | ||
const targetUser = await interaction.guild.members.fetch(targetUserID) | ||
const duration = interaction.options.getString('duration') | ||
const targetUserID = interaction.options.getUser("user"); | ||
const targetUser = await interaction.guild.members.fetch(targetUserID); | ||
const duration = interaction.options.getString("duration"); | ||
const reason = | ||
interaction.options.getString('reason') || 'No reason provided.' | ||
interaction.options.getString("reason") || "No reason provided."; | ||
|
||
const errEmbed = new EmbedBuilder().setTitle('ERROR').setColor(15548997) | ||
const errEmbed = new EmbedBuilder().setTitle("ERROR").setColor(15548997); | ||
|
||
if (!targetUser) { | ||
errEmbed.setDescription(`Looks like that user isn't in this server`) | ||
errEmbed.setDescription(`Looks like that user isn't in this server`); | ||
await interaction.editReply({ | ||
embeds: [errEmbed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
if (targetUser.bot) { | ||
errEmbed.setDescription(`You cannot timeout a bot`) | ||
errEmbed.setDescription(`You cannot timeout a bot`); | ||
await interaction.editReply({ | ||
embeds: [errEmbed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
if (targetUser.id == interaction.member.id) { | ||
errEmbed.setDescription(`You cannot timeout yourself`) | ||
errEmbed.setDescription(`You cannot timeout yourself`); | ||
await interaction.editReply({ | ||
embeds: [errEmbed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
if (targetUser.id === interaction.guild.ownerId) { | ||
errEmbed.setDescription( | ||
`You are not allowed to timeout that user. They are the server owner` | ||
) | ||
`You are not allowed to timeout that user. They are the server owner`, | ||
); | ||
await interaction.editReply({ | ||
embeds: [errEmbed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
const msDuration = ms(duration) | ||
const msDuration = ms(duration); | ||
if (isNaN(msDuration)) { | ||
errEmbed.setDescription(`Please provide a valid time duration`) | ||
await interaction.editReply({ embeds: [errEmbed] }) | ||
return | ||
errEmbed.setDescription(`Please provide a valid time duration`); | ||
await interaction.editReply({ embeds: [errEmbed] }); | ||
return; | ||
} | ||
|
||
if (msDuration < 5000 || msDuration > 2419200000) { | ||
errEmbed.setDescription( | ||
`The timeout duration must be between 5 seconds and 28 days` | ||
) | ||
await interaction.editReply({ embeds: [errEmbed] }) | ||
return | ||
`The timeout duration must be between 5 seconds and 28 days`, | ||
); | ||
await interaction.editReply({ embeds: [errEmbed] }); | ||
return; | ||
} | ||
|
||
const targetUserRolePosition = targetUser.roles.highest.position | ||
const requestUserRolePosition = interaction.member.roles.highest.position | ||
const targetUserRolePosition = targetUser.roles.highest.position; | ||
const requestUserRolePosition = interaction.member.roles.highest.position; | ||
const botRolePosition = | ||
interaction.guild.members.me.roles.highest.position | ||
interaction.guild.members.me.roles.highest.position; | ||
|
||
if (targetUserRolePosition >= requestUserRolePosition) { | ||
errEmbed.setDescription( | ||
'You cannot timeout someone higher than or equal to you' | ||
) | ||
"You cannot timeout someone higher than or equal to you", | ||
); | ||
await interaction.editReply({ | ||
embeds: [errEmbed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
if (targetUserRolePosition >= botRolePosition) { | ||
errEmbed.setDescription( | ||
'I cannot timeout someone higher than or equal to me' | ||
) | ||
"I cannot timeout someone higher than or equal to me", | ||
); | ||
await interaction.editReply({ | ||
embeds: [errEmbed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
const { default: prettyMs } = await import('pretty-ms') | ||
const { default: prettyMs } = await import("pretty-ms"); | ||
const embed = new EmbedBuilder().setColor(15548997).setFooter({ | ||
text: `Reason: ${reason}\nModerator: ${ | ||
interaction.user.username | ||
}\nDuration: ${prettyMs(msDuration)}`, | ||
}) | ||
}); | ||
|
||
const dmEmbed = new EmbedBuilder() | ||
.setColor(15548997) | ||
.setTitle(`You have been timed out!`) | ||
.setDescription( | ||
`Reason: ${reason}\nServer: ${ | ||
interaction.guild.name | ||
}\nDuration: ${prettyMs(msDuration)}` | ||
) | ||
}\nDuration: ${prettyMs(msDuration)}`, | ||
); | ||
|
||
if (!targetUser.dmChannel) await targetUser.createDM() | ||
if (!targetUser.dmChannel) await targetUser.createDM(); | ||
|
||
await targetUser.dmChannel.send({ | ||
embeds: [dmEmbed], | ||
}) | ||
}); | ||
|
||
if (targetUser.isCommunicationDisabled()) { | ||
await targetUser.timeout(msDuration, reason) | ||
await targetUser.timeout(msDuration, reason); | ||
await interaction.editReply({ | ||
content: `**${targetUser}'s timeout has been updated!**`, | ||
embeds: [embed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
if ((interaction.guild.roles.cache.find(role => role.name ==='muted')) === null) { | ||
if ( | ||
interaction.guild.roles.cache.find((role) => role.name === "muted") === | ||
null | ||
) { | ||
await interaction.editReply({ | ||
content: `**There is no muted role in this server!**`, | ||
embeds: [embed], | ||
}) | ||
return | ||
}); | ||
return; | ||
} | ||
|
||
await targetUser.roles.add(interaction.guild.roles.cache.find(role => role.name === 'muted')) | ||
await targetUser.timeout(msDuration, reason) | ||
await targetUser.roles.add( | ||
interaction.guild.roles.cache.find((role) => role.name === "muted"), | ||
); | ||
await targetUser.timeout(msDuration, reason); | ||
await interaction.editReply({ | ||
content: `**${targetUser} has been timed out!**`, | ||
embeds: [embed], | ||
}) | ||
}); | ||
await setTimeout(() => { | ||
targetUser.roles.remove(interaction.guild.roles.cache.find(role => role.name ==='muted')) | ||
targetUser.roles.remove( | ||
interaction.guild.roles.cache.find((role) => role.name === "muted"), | ||
); | ||
}, msDuration); | ||
} catch (error) { | ||
await interaction.editReply('Oops! There was an error.').then((msg) => { | ||
} | ||
catch (error) { | ||
await interaction.editReply("Oops! There was an error.").then((msg) => { | ||
setTimeout(() => { | ||
msg.delete() | ||
}, 10000) | ||
}) | ||
console.log(error) | ||
msg.delete(); | ||
}, 10000); | ||
}); | ||
console.log(error); | ||
} | ||
}, | ||
} | ||
}; |
Oops, something went wrong.