Discord
The global API for Discord events, commands, and supported guild resources. No import is required in a Weeble script.
Event-Driven Runtime
Your code registers handlers for gateway events, prefix commands, or slash
commands. Events arrive from the Discord Gateway. Weeble awaits each handler
in registration order for a dispatched event. See discord.on() for the event list.
Data on arrival, fetches when you need them
Every object (messages, members, channels, roles, …) arrives with its data
already populated from the event payload. Methods like .fetch(), .fetchGuild(),
.fetchChannel(), .fetchMember() make API calls on demand. Prefer the data you
already have. Extra fetches are slower.
discord.on(discord.events.MESSAGE_CREATE, async (msg) => {
if (msg.content === '!ping') {
await msg.reply('pong');
}
});
API calls are abstracted into methods
There is no direct access to the Discord REST API. Every mutation (sending a message, editing a role, kicking a member, banning a user) is a method on the relevant handle. Discord requests pass through Weeble’s rate limiter and may wait before being sent.
discord.on(discord.events.GUILD_MEMBER_ADD, async (member) => {
const channel = await discord.fetchGuildTextChannel('welcome-channel-id');
if (!channel) return console.warn('Welcome channel is missing or is not a text channel.');
await channel.send(`Welcome ${member.toMention()}`);
});
See also
Reference