DELETE question
mylodiscord
FREEOP

10 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

33 Replies

10 months ago

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


mylodiscord
FREEOP

10 months ago

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

1398822112507990066

1398822112738807903


10 months ago

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


mylodiscord
FREEOP

10 months ago

Nope


10 months ago

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


mylodiscord
FREEOP

10 months ago

What would you like to see?

1398823022449655808


10 months ago

Just the command that's replying twice


mylodiscord
FREEOP

10 months ago

One sec


mylodiscord
FREEOP

10 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,
        }
      });
    }
  }
};

10 months ago

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


10 months ago

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


mylodiscord
FREEOP

10 months ago

Nope, only on railway


10 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

10 months ago

Let me try again, one sec


10 months ago

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


mylodiscord
FREEOP

10 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}`);
    }
  });
};

10 months ago

That looks fine


mylodiscord
FREEOP

10 months ago

now its doing this :/

1398825115705278625


10 months ago

oh


10 months ago

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


10 months ago

Just move the event handler outside of the for loop


mylodiscord
FREEOP

10 months ago

In here right @ferret


10 months ago

Yes


10 months ago

This section should be moved outside the for loop

1398826367910543470


mylodiscord
FREEOP

10 months ago

It is tho no ?


10 months ago

oh you're right i'm just blind


10 months ago

2 space indents are tripping me up


10 months ago

Can I see where this function is called?


mylodiscord
FREEOP

10 months ago

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

1399148407645278249


mylodiscord
FREEOP

10 months ago

Nevermind, fixed!


mylodiscord
FREEOP

10 months ago

nevermind, its sending twice again


mylodiscord
FREEOP

10 months ago

1399151096882004141


mylodiscord
FREEOP

10 months ago

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


Welcome!

Sign in to your Railway account to join the conversation.

Loading...