Skip to content

Commit

Permalink
updated bot.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Oct 22, 2024
1 parent 2e02dc6 commit 6b82393
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/app/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,22 @@ export async function prepareButton(
button.options.cooldown,
`${button.options.key} button`,
{
author: interaction.user,
channel: interaction.channel,
guild: interaction.guild,
authorId: interaction.user.id,
channelId: interaction.channelId,
guildId: interaction.guildId,
},
interaction,
)

if (error) return error

if (interaction.guild) {
if (interaction.inGuild()) {
if (
button.options.adminOnly &&
!(
await interaction.guild.members.fetch(interaction.user)
await (
await interaction.client.guilds.fetch(interaction.guildId)
).members.fetch(interaction.user)
)?.permissions.has("Administrator")
) {
return util.getSystemMessage(
Expand Down
6 changes: 5 additions & 1 deletion src/app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,11 @@ export async function prepareCommand(
const error = await util.checkCooldown(
cmd.options.cooldown,
`${cmd.options.name} command`,
message,
{
authorId: message.author.id,
channelId: message.channelId,
guildId: message.guildId,
},
message,
)

Expand Down
12 changes: 6 additions & 6 deletions src/app/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ export async function checkCooldown(
cooldown: Cooldown | undefined,
key: string,
context: {
author: discord.User
guild: discord.Guild | null
channel: discord.Channel | null
authorId: discord.Snowflake
guildId: discord.Snowflake | null
channelId: discord.Snowflake | null
},
parentOfTrigger: {
triggerCooldown: () => void
Expand All @@ -673,18 +673,18 @@ export async function checkCooldown(

switch (cooldown.type) {
case CooldownType.ByUser:
_slug = slug("coolDown", key, context.author.id)
_slug = slug("coolDown", key, context.authorId)
break
case CooldownType.ByGuild:
if (context.guild) _slug = slug("coolDown", key, context.guild.id)
if (context.guildId) _slug = slug("coolDown", key, context.guildId)
else
return getSystemMessage(
"error",
"You can't perform this action outside of a guild.",
)
break
case CooldownType.ByChannel:
if (context.channel) _slug = slug("coolDown", key, context.channel.id)
if (context.channelId) _slug = slug("coolDown", key, context.channelId)
else
return getSystemMessage(
"error",
Expand Down

0 comments on commit 6b82393

Please sign in to comment.