DELETE question
mylodiscord
FREEOP

7 months ago

Can I not call DELETE with my railway server/websocket server? Trying to do this:
DELETE [https://ws.excelscrims.com/api/discord/guild/1397406168867016705/map-templates/e0773f18-ee11-4fbf-81d7-51eb1f19433e/delete](https://ws.excelscrims.com/api/discord/guild/1397406168867016705/map-templates/e0773f18-ee11-4fbf-81d7-51eb1f19433e/delete)

33 Replies

ferretcode
HOBBY

7 months ago

What's the issue? Are you receiving any status code back when you call the route?


mylodiscord
FREEOP

7 months ago

It's working now -- I'm wondering why it's replying twice? Is it because there's an extra networking or no?

1398822112507990000
1398822112738807800


ferretcode
HOBBY

7 months ago

Do you have any other deployments anywhere (e.g., one on railway, one on your local computer)


mylodiscord
FREEOP

7 months ago

Nope


ferretcode
HOBBY

7 months ago

I'd have to see the code then if you can share


mylodiscord
FREEOP

7 months ago

What would you like to see?

1398823022449655800


ferretcode
HOBBY

7 months ago

Just the command that's replying twice


mylodiscord
FREEOP

7 months ago

One sec


mylodiscord
FREEOP

7 months ago

const lobbiesSchema = require("../../../models/lobbiesData");

module.exports = {
  name: "add",
  description: "Adds a player in the current lobby",

  async execute(message, args) {
    const target = message.mentions.users.first() || await message.client.users.fetch(args[0]).catch(() => null);
    if (!target) return message.reply(":x: Please mention a user or provide a valid user ID.");

    const guildId = message.guild.id;
    const channelId = message.channel.id;

    const allLobbies = await lobbiesSchema.find({ guildId });
    const lobby = allLobbies.find(l => {
      return Object.values(l.channels || {}).some(ch => ch?.toString() === channelId.toString());
    });

    if (!lobby) {
      return message.reply(":x: Could not find a lobby associated with this channel.");
    }

    const alreadyRegistered = lobby.teams.find(team => team.discordId === target.id);
    if (alreadyRegistered) {
      return message.reply(":warning: User is already registered in this lobby.");
    }

    const member = await message.guild.members.fetch(target.id);
    const highestIconRole = member.roles.cache
      .filter(role => role.icon)
      .sort((a, b) => b.position - a.position)
      .first();

    const highestVisualRole = member.roles.cache
      .filter(r => r.id !== message.guild.id)
      .sort((a, b) => b.position - a.position)
      .first();

    const highestRoleBadgeIcon = highestIconRole?.iconURL() ?? null;
    const highestRoleColor = highestVisualRole?.hexColor ?? null;

    const teamEntry = {
      discordId: target.id,
      discordName: target.username,
      profilePicture: target.displayAvatarURL({ extension: "png", size: 128 }),
      registeredAt: new Date(),
      highestRoleBadgeIcon,
      hexColor: highestRoleColor,
    };

    lobby.teams.push(teamEntry);
    lobby.registeredTeams += 1;
    await lobby.save();

    message.reply(`Added ${target} to **${lobby.lobbyName}**.`);

    if (global.io) {
      global.io.emit("team-added", {
        lobbyId: lobby.lobbyId,
        user: {
          id: target.id,
          name: target.username,
          avatar: teamEntry.profilePicture,
          registeredAt: teamEntry.registeredAt,
          highestRoleBadgeIcon,
          hexColor: highestRoleColor,
        }
      });
    }
  }
};

ferretcode
HOBBY

7 months ago

The most reasonable answer would be that there are multiple deployments trying to process your message at once


ferretcode
HOBBY

7 months ago

You're 100% sure you weren't running the bot locally & on Railway


mylodiscord
FREEOP

7 months ago

Nope, only on railway


ferretcode
HOBBY

7 months ago

Is it possible that you ran that command when a new build had just finished & was deploying before the previous deployment had been removed?


mylodiscord
FREEOP

7 months ago

Let me try again, one sec


ferretcode
HOBBY

7 months ago

Also, does your command handler ignore users who are bots or not the original sender?


mylodiscord
FREEOP

7 months ago

This is my command handler:

const fs = require("fs");
const path = require("path");

module.exports = (client) => {
  client.prefixCommands = new Map();

  const commandDir = path.join(__dirname, "..", "commands", "prefix-commands");
  const commandFiles = fs.readdirSync(commandDir).filter(file => file.endsWith(".js"));

  for (const file of commandFiles) {
    const command = require(path.join(commandDir, file));
    client.prefixCommands.set(command.name, command);
    console.log(`✅ Loaded prefix command: ${command.name}`);
  }

  client.on("messageCreate", async (message) => {
    if (message.author.bot || !message.content.startsWith("*")) return;

    const args = message.content.slice(1).trim().split(/ +/);
    const commandName = args.shift()?.toLowerCase();

    const command = client.prefixCommands.get(commandName);
    if (!command) return;

    try {
      await command.execute(message, args);
    } catch (error) {
      console.error(":x: Error executing command:", error);
      await message.reply(`❌ Error executing command: ${error.message}`);
    }
  });
};

ferretcode
HOBBY

7 months ago

That looks fine


mylodiscord
FREEOP

7 months ago

now its doing this :/

1398825115705278700


ferretcode
HOBBY

7 months ago

oh


ferretcode
HOBBY

7 months ago

It's because you're subscribing to the messageCreate event every time you register a command in the command handler


ferretcode
HOBBY

7 months ago

Just move the event handler outside of the for loop


mylodiscord
FREEOP

7 months ago

In here right @ferret


ferretcode
HOBBY

7 months ago

Yes


ferretcode
HOBBY

7 months ago

This section should be moved outside the for loop

1398826367910543400


mylodiscord
FREEOP

7 months ago

It is tho no ?


ferretcode
HOBBY

7 months ago

oh you're right i'm just blind


ferretcode
HOBBY

7 months ago

2 space indents are tripping me up


ferretcode
HOBBY

7 months ago

Can I see where this function is called?


mylodiscord
FREEOP

7 months ago

Hi again, I fixed the issue I'm pretty sure. But everytime I do npm start it returns with this

1399148407645278200


mylodiscord
FREEOP

7 months ago

Nevermind, fixed!


mylodiscord
FREEOP

7 months ago

nevermind, its sending twice again


mylodiscord
FREEOP

7 months ago

1399151096882004200


mylodiscord
FREEOP

7 months ago

Got it working i reset the token and seems to done the trick


Loading...