-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
95 additions
and
55 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,50 +1,107 @@ | ||
const { Collection, Events } = require("discord.js"); | ||
const { | ||
Collection, | ||
ChannelType, | ||
PermissionFlagsBits, | ||
Events, | ||
} = require("discord.js"); | ||
|
||
module.exports = { | ||
name: Events.InteractionCreate, | ||
async execute(interaction) { | ||
if (!interaction.isChatInputCommand()) return; | ||
if (interaction.isChatInputCommand()) { | ||
// respond to the Chat | ||
|
||
const command = interaction.client.commands.get(interaction.commandName); | ||
const command = interaction.client.commands.get(interaction.commandName); | ||
|
||
if (!command) { | ||
console.error( | ||
`No command matching ${interaction.commandName} was found.`, | ||
); | ||
return; | ||
} | ||
if (!command) { | ||
console.error( | ||
`No command matching ${interaction.commandName} was found.`, | ||
); | ||
return; | ||
} | ||
|
||
const { cooldowns } = interaction.client; | ||
const { cooldowns } = interaction.client; | ||
|
||
if (!cooldowns.has(command.data.name)) { | ||
cooldowns.set(command.data.name, new Collection()); | ||
} | ||
if (!cooldowns.has(command.data.name)) { | ||
cooldowns.set(command.data.name, new Collection()); | ||
} | ||
|
||
const now = Date.now(); | ||
const timestamps = cooldowns.get(command.data.name); | ||
const defaultCooldownDuration = 3; | ||
const cooldownAmount = | ||
(command.cooldown ?? defaultCooldownDuration) * 1000; | ||
|
||
if (timestamps.has(interaction.user.id)) { | ||
const expirationTime = | ||
timestamps.get(interaction.user.id) + cooldownAmount; | ||
|
||
const now = Date.now(); | ||
const timestamps = cooldowns.get(command.data.name); | ||
const defaultCooldownDuration = 3; | ||
const cooldownAmount = (command.cooldown ?? defaultCooldownDuration) * 1000; | ||
|
||
if (timestamps.has(interaction.user.id)) { | ||
const expirationTime = | ||
timestamps.get(interaction.user.id) + cooldownAmount; | ||
|
||
if (now < expirationTime) { | ||
const expiredTimestamp = Math.round(expirationTime / 1000); | ||
return interaction.reply({ | ||
content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again <t:${expiredTimestamp}:R>.`, | ||
ephemeral: true, | ||
}); | ||
if (now < expirationTime) { | ||
const expiredTimestamp = Math.round(expirationTime / 1000); | ||
return interaction.reply({ | ||
content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again <t:${expiredTimestamp}:R>.`, | ||
ephemeral: true, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
await command.execute(interaction); | ||
timestamps.set(interaction.user.id, now); | ||
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount); | ||
} catch (error) { | ||
console.error(`Error executing ${interaction.commandName}`); | ||
console.error(error); | ||
try { | ||
await command.execute(interaction); | ||
timestamps.set(interaction.user.id, now); | ||
setTimeout( | ||
() => timestamps.delete(interaction.user.id), | ||
cooldownAmount, | ||
); | ||
} catch (error) { | ||
console.error(`Error executing ${interaction.commandName}`); | ||
console.error(error); | ||
} | ||
} else if (interaction.isButton()) { | ||
// respond to the button | ||
try { | ||
let channel; | ||
await interaction.deferReply({ ephemeral: true }); | ||
switch (interaction.customId) { | ||
case "open-ticket": | ||
try { | ||
channel = await interaction.guild.channels.create({ | ||
name: `t-${interaction.user.username}`, | ||
type: ChannelType.GuildText, | ||
permissionOverwrites: [ | ||
{ | ||
id: interaction.user.id, | ||
allow: [PermissionFlagsBits.ViewChannel], | ||
}, | ||
{ | ||
id: interaction.guild.roles.everyone.id, | ||
deny: [PermissionFlagsBits.ViewChannel], | ||
}, | ||
], | ||
}); | ||
|
||
channel.send({ | ||
content: `<@${interaction.user.id}>`, | ||
// embeds: [ticketEmbed], | ||
// components: [new ActionRowBuilder().addComponents(openTicket)], | ||
}); | ||
|
||
await interaction.editReply( | ||
`Ticket is been created, move on <#${channel.id}>`, | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} catch (error) { | ||
console.error(`Error executing ${interaction.customId}`); | ||
console.error(error); | ||
} | ||
} else if (interaction.isStringSelectMenu()) { | ||
// respond to the select menu | ||
} | ||
}, | ||
}; |