Skip to content

Commit

Permalink
Fix bot replying too late
Browse files Browse the repository at this point in the history
  • Loading branch information
fowled committed Nov 21, 2022
1 parent 175adf4 commit b7abbd0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 88 deletions.
22 changes: 2 additions & 20 deletions app/src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,13 @@ module.exports = {

if (!interaction.isChatInputCommand() || !interaction.isCommand() || !clientInteractions.has(interaction.commandName)) return;

await interaction.deferReply();

const args = interaction.options.data.filter((data) => data.type !== Discord.ApplicationCommandOptionType.Subcommand).map((opt) => opt.value.toString());
const command = interaction.commandName;

const commandInteraction = clientInteractions.get(command);
const interactionMember = interaction.member as Discord.GuildMember;
const cachedIds = [];

if (!(interaction.user.id in cachedIds)) {
const fetchDBAccount = await supabase.from("users").select("user_id").eq("user_id", interaction.user.id).single();

if (!fetchDBAccount.data) {
await supabase.from("users").insert({
user_id: interaction.user.id,
money: 500,
guilds: await fetchMutualServers(),
inventory: [],
});
} else {
await supabase.from("users").update({ guilds: await fetchMutualServers() }).like("user_id", interaction.user.id);
}

cachedIds.push(interaction.user.id);
}

if (commandInteraction.memberPermissions && !interactionMember.permissions.has(commandInteraction.memberPermissions as Discord.PermissionResolvable)) {
return interaction.reply({
Expand All @@ -50,8 +34,6 @@ module.exports = {
});
}

await interaction.deferReply();

try {
await commandInteraction.execute(Client, interaction, args, supabase);
} catch (err) {
Expand Down
96 changes: 29 additions & 67 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion website/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.env
.env
dist/

0 comments on commit b7abbd0

Please sign in to comment.