Home > Software engineering >  Discord.js timeout Invalid communication disabled timestamp
Discord.js timeout Invalid communication disabled timestamp

Time:11-05

I'm trying to build a discord bot for my server. This bot includes a mute command that should timeout the target user. I'm using NodeJS and added the ms package. The duration also gets converted into milliseconds just fine, but when I try to timeout someone for 30d the bot crashes:

/root/etl-bot/node_modules/@discordjs/rest/dist/index.js:659
        throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
              ^

DiscordAPIError[50035]: Invalid Form Body
communication_disabled_until[INVALID_COMMUNICATION_DISABLED_TIMESTAMP]: Invalid communication disabled timestamp
    at SequentialHandler.runRequest (/root/etl-bot/node_modules/@discordjs/rest/dist/index.js:659:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SequentialHandler.queueRequest (/root/etl-bot/node_modules/@discordjs/rest/dist/index.js:458:14)
    at async REST.request (/root/etl-bot/node_modules/@discordjs/rest/dist/index.js:902:22)
    at async GuildMemberManager.edit (/root/etl-bot/node_modules/discord.js/src/managers/GuildMemberManager.js:325:15) {
  requestBody: {
    files: undefined,
    json: {
      communicationDisabledUntil: 1670184017237,
      communication_disabled_until: '2022-12-04T20:00:17.237Z'
    }
  },
  rawError: {
    code: 50035,
    errors: {
      communication_disabled_until: {
        _errors: [
          {
            code: 'INVALID_COMMUNICATION_DISABLED_TIMESTAMP',
            message: 'Invalid communication disabled timestamp'
          }
        ]
      }
    },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'PATCH',
  url: 'https://discord.com/api/v10/guilds/832685267773030401/members/914947955763605554'
}

Didn't really try anything yet, cause I don't know what to try. Is there any limit by discord for the GuildMember#timeout() function? I don't seem to find any so I'll try it here

This is the relevant code:

const target = message.mentions.members.first();
const time = args[2];
const reason = args.slice(3).join(' ');
const convertedTime = ms(time);
if (!convertedTime) {
  const embed = new EmbedBuilder()
    .setColor(error)
    .setTitle(`${questionEmoji}`)
    .setDescription(`**Fehler**\nVerwende \`?mute @User Dauer Grund\``)
    .setFooter({
      text: 'Diese Nachricht löscht sich in 5 Sekunden',
    });
  await message.reply({ embeds: [embed] }).then(async (msg) => {
    setTimeout(async () => {
      msg.delete();
      message.delete();
    }, 5000);
  });
}
if (target.isCommunicationDisabled()) {
  const embed = new EmbedBuilder()
    .setColor(error)
    .setTitle(`${questionEmoji}`)
    .setDescription(`**Fehler**\nDieser Spieler ist bereits gesperrt.`)
    .setFooter({
      text: 'Diese Nachricht löscht sich in 5 Sekunden',
    });
  await message.reply({ embeds: [embed] }).then(async (msg) => {
    setTimeout(async () => {
      msg.delete();
      message.delete();
    }, 5000);
  });
  return;
}
try {
  const embed = new EmbedBuilder()
    .setColor(success)
    .setTitle(`${checkReply}`)
    .setDescription(
      `**Erfolg**\n**${target}** wurde wegen **${reason}** für **${time}** gesperrt.`,
    );
  message.reply({ embeds: [embed] });
  const embed2 = new EmbedBuilder()
    .setColor(primary)
    .setTitle(`${emEmoji}`)
    .setDescription(
      `**Sperre**\n**${target}** wurde von **${message.author}** wegen **${reason}** für **${time}** gesperrt.`,
    );
  teamchat.send({ embeds: [embed2] });
  target.timeout(convertedTime, reason);
} catch (err) {
  console.log(err);
}

CodePudding user response:

Is there any limit by discord for the GuildMember#timeout() function? I don't seem to find any

Yes, there is and it's 28 days. It's strange that there is nothing about it in the discord.js documentation. However, you can find it on the Discord Developer Portal:

communication_disabled_until

ISO8601 timestamp

when the user's timeout will expire and the user will be able to communicate in the guild again (up to 28 days in the future), set to null to remove timeout. Will throw a 403 error if the user has the ADMINISTRATOR permission or is the owner of the guild

It means that you should check if the value of convertedTime is less than 2419200000 or 28 * 24 * 60 * 60 * 1000

  • Related