Skip to content

Instantly share code, notes, and snippets.

@Kaisarion
Created March 18, 2022 16:30
Show Gist options
  • Save Kaisarion/a39cdb7cabeb0e96301be6b1838e1e91 to your computer and use it in GitHub Desktop.
Save Kaisarion/a39cdb7cabeb0e96301be6b1838e1e91 to your computer and use it in GitHub Desktop.
THIS IS BEA AFTER SHE KNOWS HOW TO WORK OPTIONS ON DJS!!!
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed, Permissions } = require("discord.js");
const DatabaseManager = require("../../handlers/DatabaseManager.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("timeout")
.setDescription("Timeout a mentioned user in the server.")
.addUserOption((option) =>
option
.setName("timeoutuser")
.setDescription("The user to kick from the server.")
.setRequired(true)
)
.addIntegerOption((option) =>
option
.setName("time")
.setDescription("The time the user should be timed out for.")
.setRequired(true)
.addChoice("1 Minute", 60000)
.addChoice("5 Minutes", 300000)
.addChoice("10 Minutes", 600000)
.addChoice("1 Hour", 3600000)
.addChoice("1 Day", 86400000)
.addChoice("1 Week", 604800000)
.addChoice("Off", 0)
)
.addStringOption((option) =>
option
.setName("timeoutreason")
.setDescription("The reason for timing out the mentioned user.")
),
async execute(interaction) {
const embedcolor = await DatabaseManager.getHexColor(interaction.guild.id);
const usr = interaction.options.getUser("timeoutuser");
const mem = await interaction.guild.members.fetch(usr);
let rs = interaction.options.getString("timeoutreason");
if (!rs) rs = "unspecified";
// modlogs
const logChannel = await DatabaseManager.getGuildModLogsID(
interaction.guild.id
);
const ModLogsCh = await interaction.guild.channels.cache.get(logChannel);
if (!interaction.member.permissions.has(Permissions.FLAGS.KICK_MEMBERS))
return interaction.reply(
"❌ **ERROR !** \n" +
"you do not have permissions to use this command. if you believe this is in error, contact the server staff team."
);
if (!interaction.guild.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS))
return interaction.reply(
"❌ **ERROR !** \n" +
"I don't have the right permissions! if you believe this is in error, please check my role permissions."
);
const owner = await interaction.guild.fetchOwner();
if (owner.id !== interaction.user.id) {
if (
member.roles.highest.rawPosition >=
interaction.member.roles.highest.rawPosition
) {
return message.channel.send(
"This user can't be timed out because they have the same or higher role to you."
);
}
}
let time = interaction.options.get("time");
let val = time.value;
if (val === 0) val = null;
let timename;
// Handle the time name
switch (true) {
case val === 60000:
timename = `${val / 60000} minute`;
break;
case val === 3000000:
timename = `${val / 60000} minutes`;
break;
case val === 6000000:
timename = `${val / 60000} minutes`;
break;
case val === 3600000:
timename = `${val / 1000 / 3600} hour`;
break;
case val === 86400000:
timename = `${val / 86400000} day`;
break;
case val === 604800000:
timename = `${val / (1000 * 60 * 60 * 24 * 7)} week`;
break;
case val === null:
timename = "Timeout Removed";
break;
}
const timeoutembed = new MessageEmbed()
.setColor(embedcolor)
.setAuthor({
name: interaction.user.username,
iconURL: interaction.user.displayAvatarURL({ dynamic: true }),
})
.setTitle(
`🔇 You have been timed out in ${interaction.guild.name} for ${timename}`
)
.setDescription(`**Reason:** ${rs}`);
const done = new MessageEmbed()
.setTitle("Member Timed Out")
.setColor(embedcolor)
.setThumbnail(usr.displayAvatarURL())
.addField("User Timed Out", `${usr} (${usr.tag})`)
.addField("User ID", usr.id)
.setDescription(`Timed out for ${rs} for ${timename}`)
.setTimestamp();
if (val === null) {
timeoutembed.setTitle(
`🔇 Your timeout in ${interaction.guild.name} has been removed`
);
done.setTitle('Member Timeout Removed')
done.addField("Timeout removed by", `${interaction.user} (${interaction.user.id})`)
done.setDescription(`Timed out removed for ${rs}`)
} else {
done.addField("Timed out by", `${interaction.user} (${interaction.user.id})`)
}
mem
.timeout(val, `${interaction.user.tag} ;; ${rs} `)
.then(async () => {
await usr
.send({ embeds: [timeoutembed] })
.catch((err) =>
interaction.channel.send(`I could not DM the user! Reason: ${err}`)
);
interaction.reply({ embeds: [done] });
if (logChannel === "" || !logChannel) {
return interaction.reply({ embeds: [done] });
} else {
if (ModLogsCh)
ModLogsCh.send({ embeds: [done] }).catch((err) =>
message.channel.send(err)
);
return;
}
})
.catch((err) => {
if (err)
return interaction.reply(
"Something went wrong. If this issue persists, please use /amourhelp"
);
});
},
};
@Kaisarion
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment