import { Client, GatewayDispatchEvents, GatewayIntentBits, InteractionType, MessageFlags } from '@discordjs/core';
import { REST } from '@discordjs/rest';
import { WebSocketManager } from '@discordjs/ws';
import { DurationFormatter } from '@sapphire/duration';
import { RateLimitManager } from '@sapphire/ratelimits';
import { Time } from '@sapphire/timestamp';
import { token } from './config.js';
const rest = new REST({ version: '10' }).setToken(token);
const ws = new WebSocketManager({
token,
intents: GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent,
rest,
});
const client = new Client({ rest, ws });
const formatter = new DurationFormatter();
const rateLimitManager = new RateLimitManager(Time.Day, 50);
const ratelimit = rateLimitManager.acquire('global');
client.on(GatewayDispatchEvents.InteractionCreate, async ({ data: interaction, api }) => {
console.log(interaction);
if (interaction.type !== InteractionType.ApplicationCommand || interaction.data.name !== 'ask') return;
if (ratelimit.limited) {
await api.interactions.reply(interaction.id, interaction.token, {
content: `The command is on a cooldown.\nYou'll be able to use the commands again in ${formatter.format(
ratelimit.remainingTime,
)}`,
});
return;
}
await api.interactions.reply(interaction.id, interaction.token, { content: 'Pong!', flags: MessageFlags.Ephemeral });
ratelimit.consume();
});
import { Client, GatewayDispatchEvents, GatewayIntentBits, InteractionType, MessageFlags } from '@discordjs/core';
import { REST } from '@discordjs/rest';
import { WebSocketManager } from '@discordjs/ws';
import { DurationFormatter } from '@sapphire/duration';
import { RateLimitManager } from '@sapphire/ratelimits';
import { Time } from '@sapphire/timestamp';
import { token } from './config.js';
const rest = new REST({ version: '10' }).setToken(token);
const ws = new WebSocketManager({
token,
intents: GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent,
rest,
});
const client = new Client({ rest, ws });
const formatter = new DurationFormatter();
const rateLimitManager = new RateLimitManager(Time.Day, 50);
const ratelimit = rateLimitManager.acquire('global');
client.on(GatewayDispatchEvents.InteractionCreate, async ({ data: interaction, api }) => {
console.log(interaction);
if (interaction.type !== InteractionType.ApplicationCommand || interaction.data.name !== 'ask') return;
if (ratelimit.limited) {
await api.interactions.reply(interaction.id, interaction.token, {
content: `The command is on a cooldown.\nYou'll be able to use the commands again in ${formatter.format(
ratelimit.remainingTime,
)}`,
});
return;
}
await api.interactions.reply(interaction.id, interaction.token, { content: 'Pong!', flags: MessageFlags.Ephemeral });
ratelimit.consume();
});