Discord
Events, commands, and the guild’s channels, members, roles, and messages.
discord is a global, so there is nothing to import.
Events
Register handlers with discord.on(). When an event arrives from the Discord
gateway, Weeble runs its handlers one at a time, in the order you registered
them. See discord.events for the full list.
Event data and fetches
Objects in an event, such as the message or the member, arrive with their data
filled in. Methods named fetch*(), such as fetchGuild() or fetchMember(),
ask Discord for data the event didn’t include. Use what the event gave you
first: every fetch is another request.
discord.on(discord.events.MESSAGE_CREATE, async (msg) => {
if (msg.content === '!ping') {
await msg.reply('pong');
}
});
Changing things
Scripts can’t call the Discord REST API directly. To send a message, edit a role, or ban a member, call the method on that object. Requests go through Weeble’s rate limiter and can wait before they are 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