Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/role spam #54

Open
Gaute945 opened this issue Jul 15, 2024 · 0 comments
Open

/role spam #54

Gaute945 opened this issue Jul 15, 2024 · 0 comments
Assignees

Comments

@Gaute945
Copy link
Owner

Gaute945 commented Jul 15, 2024

add a cooldown for /role and make the roles not apear in the side bar

Rationale

server owners are complaining about /role getting spammed, filling the role slots and side bar

this would get more servers to enable /role

Implementation Details

Cooldowns | discord.js Guide
using maps for per server cooldown

const cooldowns = new Map();
client.on("interactionCreate", async (interaction) => {
  if (!interaction.isChatInputCommand()) return;

  const { commandName, guildId } = interaction;
  const now = Date.now();
  const cooldownAmount = 3 * 1000; // Cooldown time in milliseconds (3 seconds here)

  if (!cooldowns.has(commandName)) {
    cooldowns.set(commandName, new Map());
  }

  const timestamps = cooldowns.get(commandName);
  const expirationTime = timestamps.get(guildId) + cooldownAmount;

  if (timestamps.has(guildId)) {
    if (now < expirationTime) {
      const timeLeft = (expirationTime - now) / 1000;
      return interaction.reply({
        content: `Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${commandName}\` command.`,
        ephemeral: true,
      });
    }
  }

  timestamps.set(guildId, now);
  setTimeout(() => timestamps.delete(guildId), cooldownAmount);

  // Your command logic here
  // Existing command logic follows...
});

Explanation

  • Cooldown Map: A cooldowns map is initialized to keep track of cooldowns for each command.

  • Interaction Handling: For each command, it checks if the user is on cooldown. If so, it replies with the remaining cooldown time. Otherwise, it sets a cooldown for the user and proceeds with the command execution.

  • Command Logic: The existing command logic remains unchanged and is executed if the user is not on cooldown.

Additional Information

code above is from chatGPT
remember to disable roles in side bar


Note:

  • If you are planning to work on this feature, please comment on this issue to express your interest.
  • Follow the Feature Requests and Contributions guidelines in the contributing documentation before submitting your proposal.
@Gaute945 Gaute945 self-assigned this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant