Skip to content

Bot

Top level documentation for the Discord-Luau library, welcome! 👋

This package will represent the entrypoint to your adventure using Discord-Luau, through this package you’ll generate a discord Bot object, this bot Object enables you to write discord bots for the Discord API.

local DiscordLuau = require("/path/to/discord-luau")
local Bot = DiscordLuau.bot -- This module!
local discordBot = Bot.new({
token = env.DISCORD_BOT_TOKEN,
reconnect = env.IS_PRODUCTION,
intents = 513, -- Guild, GuildMessages
})
discordBot:connectAsync():await()
print(`Bot has connected: '{discordBot.user.username}'`)

Summary

Properties

Bot.state :: State.StateBot.logger :: LoggerBot.application :: Classes.Application?Bot.user :: Classes.User?Bot.onReady :: Emitter<number>Bot.onAllShardsReady :: Emitter<()>Bot.onShardDisconnected :: Emitter<number, string>Bot.onShardReconnected :: Emitter<number>Bot.onMessage :: Emitter<Classes.Message>Bot.onMessageChanged :: Emitter<Classes.Message>Bot.onMessageDeleted :: Emitter<{ messageId: apiTypes.Snowflake, channelId: apiTypes.Snowflake, guildId: apiTypes.Snowflake? }>Bot.onMessageBulkDeleted :: Emitter<{ channelId: string, guildId: string?, ids: { string } }>Bot.onGroupDMChannelCreate :: Emitter<Classes.GroupDM>Bot.onCategoryChannelCreate :: Emitter<Classes.GuildCategory>Bot.onAnnouncementChannelCreate :: Emitter<Classes.GuildAnnouncement>Bot.onDirectoryChannelCreate :: Emitter<Classes.GuildDirectory>Bot.onDMChannelCreate :: Emitter<Classes.DM>Bot.onTextChannelCreate :: Emitter<Classes.GuildText>Bot.onVoiceChannelCreate :: Emitter<Classes.GuildVoice>Bot.onStageVoiceChannelCreate :: Emitter<Classes.GuildStageVoice>Bot.onGroupDMChannelUpdated :: Emitter<Classes.GroupDM>Bot.onCategoryChannelUpdated :: Emitter<Classes.GuildCategory>Bot.onAnnouncementChannelUpdated :: Emitter<Classes.GuildAnnouncement>Bot.onDirectoryChannelUpdated :: Emitter<Classes.GuildDirectory>Bot.onDMChannelUpdated :: Emitter<Classes.DM>Bot.onTextChannelUpdated :: Emitter<Classes.GuildText>Bot.onVoiceChannelUpdated :: Emitter<Classes.GuildVoice>Bot.onStageVoiceChannelUpdated :: Emitter<Classes.GuildStageVoice>Bot.onGroupDMChannelDeleted :: Emitter<Classes.GroupDM>Bot.onCategoryChannelDeleted :: Emitter<Classes.GuildCategory>Bot.onAnnouncementChannelDeleted :: Emitter<Classes.GuildAnnouncement>Bot.onDirectoryChannelDeleted :: Emitter<Classes.GuildDirectory>Bot.onDMChannelDeleted :: Emitter<Classes.DM>Bot.onTextChannelDeleted :: Emitter<Classes.GuildText>Bot.onVoiceChannelDeleted :: Emitter<Classes.GuildVoice>Bot.onStageVoiceChannelDeleted :: Emitter<Classes.GuildStageVoice>Bot.onUserUpdated :: Emitter<Classes.User>Bot.onChannelPinsUpdate :: Emitter<{ guildId: string, channelId: string, lastPinTimestamp: stdPolyfills.DateTime? }>Bot.onGuildCreate :: Emitter<classes.UnavailableGuild | classes.Guild>Bot.onGuildUpdate :: Emitter<Classes.Guild>Bot.onGuildDelete :: Emitter<Classes.UnavailableGuild>Bot.onGuildMemberBanned :: Emitter<{ guildId: string, user: classes.User }>Bot.onGuildMemberUnbanned :: Emitter<{ guildId: string, user: classes.User }>Bot.onGuildMemberJoined :: Emitter<{ guildId: string, member: Classes.GuildMember }>Bot.onGuildMemberLeft :: Emitter<{ guildId: string, user: classes.User }>Bot.onGuildMemberUpdated :: Emitter<{guildId: string,roles: { string },user: classes.User,nick: string?,avatar: string?,joinedAt: stdPolyfills.DateTime?,premiumSince: stdPolyfills.DateTime?,deaf: boolean?,mute: boolean?,pending: boolean?,communicationDisabledUntil: stdPolyfills.DateTime?,}>Bot.onPingInteraction :: Emitter<Classes.Ping>Bot.onCommandInteraction :: Emitter<Classes.TypesCommand>Bot.onComponentInteraction :: Emitter<Classes.Component>Bot.onAutocompleteInteraction :: Emitter<Classes.Autocomplete>Bot.onModalInteraction :: Emitter<Classes.Modal>Bot.onMessageReactionAdd :: Emitter<{ userId: string, channelId: string, messageId: string, guildId: string?, member: Classes.GuildMember?, emoji: Classes.Emoji, messageAuthorId: string?, burst: boolean, burstColors: { string }, reactionType: number }>Bot.onMessageReactionRemove :: Emitter<{ userId: string, channelId: string, messageId: string, guildId: string?, emoji: Classes.Emoji, burst: boolean, reactionType: number }>Bot.onMessageReactionRemoveAll :: Emitter<{ channelId: string, messageId: string, guildId: string? }>Bot.onMessageReactionRemoveEmoji :: Emitter<{ channelId: string, messageId: string, guildId: string?, emoji: Classes.Emoji }>Bot.onThreadListSync :: Emitter<{ guildId: string, channelIds: { string }?, members: { Classes.ThreadMember } }>Bot.onThreadMemberUpdate :: Emitter<{ guildId: string, threadMember: Classes.ThreadMember }>Bot.onThreadMembersUpdate :: Emitter<{ id: string, guildId: string, memberCount: number, addedMembers: { Classes.ThreadMember }, removedMemberIds: { string }? }>Bot.onEntitlementCreate :: Emitter<Classes.Entitlement>Bot.onEntitlementUpdate :: Emitter<Classes.Entitlement>Bot.onEntitlementDelete :: Emitter<Classes.Entitlement>Bot.onGuildAuditLogEntryCreate :: Emitter<Classes.AuditLogEntry>Bot.onGuildEmojisUpdate :: Emitter<{ guildId: string, emojis: { Classes.Emoji } }>Bot.onGuildStickersUpdate :: Emitter<{ guildId: string, stickers: { Classes.Sticker } }>Bot.onGuildScheduledEventCreate :: Emitter<Classes.ScheduledEvent>Bot.onGuildScheduledEventUpdate :: Emitter<Classes.ScheduledEvent>Bot.onGuildScheduledEventDelete :: Emitter<Classes.ScheduledEvent>Bot.onGuildScheduledEventUserAdd :: Emitter<{ guildScheduledEventId: string, userId: string, guildId: string }>Bot.onGuildScheduledEventUserRemove :: Emitter<{ guildScheduledEventId: string, userId: string, guildId: string }>Bot.onIntegrationCreate :: Emitter<Classes.Integration>Bot.onIntegrationUpdate :: Emitter<Classes.Integration>Bot.onIntegrationDelete :: Emitter<{ id: string, guildId: string, applicationId: string? }>Bot.onInviteCreate :: Emitter<{ channelId: string, code: string, createdAt: stdPolyfills.DateTime, guildId: string?, inviter: Classes.User?, maxAge: number, maxUses: number, targetType: number?, targetUser: Classes.User?, temporary: boolean, uses: number }>Bot.onInviteDelete :: Emitter<{ channelId: string, code: string, guildId: string? }>Bot.onAutoModerationRuleCreate :: Emitter<Classes.AutomoderationRule>Bot.onAutoModerationRuleUpdate :: Emitter<Classes.AutomoderationRule>Bot.onAutoModerationRuleDelete :: Emitter<Classes.AutomoderationRule>Bot.onAutoModerationActionExecution :: Emitter<{ guildId: string, action: apiTypes.AutomoderationActionObject, ruleId: string, ruleTriggerType: apiTypes.AutomoderationRuleTriggerType, userId: string, channelId: string?, messageId: string?, alertSystemMessageId: string?, content: string, matchedKeyword: string?, matchedContent: string? }>Bot.onApplicationCommandPermissionsUpdate :: Emitter<{ id: string, applicationId: string, guildId: string, permissions: { apiTypes.GuildApplicationCommandPermissionObject } }>Bot.onMessagePollVoteAdd :: Emitter<{ userId: string, channelId: string, messageId: string, guildId: string?, answerId: number }>Bot.onMessagePollVoteRemove :: Emitter<{ userId: string, channelId: string, messageId: string, guildId: string?, answerId: number }>Bot.onGuildRoleCreate :: Emitter<Classes.Role>Bot.onGuildRoleUpdate :: Emitter<Classes.Role>Bot.onGuildRoleDelete :: Emitter<{ guildId: string, roleId: string }>Bot.onAnnouncementThreadCreate :: Emitter<Classes.Announcement>Bot.onPublicThreadCreate :: Emitter<Classes.Public>Bot.onPrivateThreadCreate :: Emitter<Classes.Private>Bot.onAnnouncementThreadUpdate :: Emitter<Classes.Announcement>Bot.onPublicThreadUpdate :: Emitter<Classes.Public>Bot.onPrivateThreadUpdate :: Emitter<Classes.Private>Bot.onThreadDelete :: Emitter<{ id: string, guildId: string, parentId: string, type: number }>Bot.onPresenceUpdate :: Emitter<Classes.Presence>Bot.onTypingStart :: Emitter<{ channelId: string, guildId: string?, userId: string, timestamp: number, member: Classes.GuildMember? }>Bot.onGuildMembersChunk :: Emitter<{ guildId: string, members: { Classes.GuildMember }, chunkIndex: number, chunkCount: number, notFound: { string }?, nonce: string? }>Bot.onGuildIntegrationsUpdate :: Emitter<{ guildId: string }>Bot.onWebhooksUpdate :: Emitter<{ guildId: string, channelId: string }>Bot.onResumed :: Emitter<()>Bot.onVoiceStateUpdate :: Emitter<Classes.VoiceState>Bot.onVoiceServerUpdate :: Emitter<{ token: string, guildId: string, endpoint: string? }>Bot.onStageInstanceCreate :: Emitter<Classes.StageInstance>Bot.onStageInstanceUpdate :: Emitter<Classes.StageInstance>Bot.onStageInstanceDelete :: Emitter<Classes.StageInstance>Bot.onGuildSoundboardSoundCreate :: Emitter<Classes.SoundboardSound>Bot.onGuildSoundboardSoundUpdate :: Emitter<Classes.SoundboardSound>Bot.onGuildSoundboardSoundDelete :: Emitter<{ soundId: string, guildId: string }>Bot.onGuildSoundboardSoundsUpdate :: Emitter<{ guildId: string, soundboardSounds: { Classes.SoundboardSound } }>Bot.onVoiceChannelEffectSend :: Emitter<{ channelId: string, guildId: string, userId: string, emoji: Classes.Emoji?, animationType: number?, animationId: number?, soundId: string?, soundVolume: number? }>Bot.onRateLimited :: Emitter<{ opcode: number, retryAfter: number, guildId: string? }>

Methods

Bot:queryGatewayInformation()future.FutureLike<string, apiTypes.GetGatewayBotResponse>Bot:connectAsync()future.FutureLike<string, nil>Bot:listDefaultSoundboardSoundsAsync()future.FutureLike<string, { classes.SoundboardSound }>Bot:getGuildAsync(guildId: string, withCount: boolean?)future.FutureLike<string, classes.Guild>Bot:getChannelAsync(channelId: string)future.FutureLike<string, classes.Channel>Bot:getDMChannelAsync(channelId: string)future.FutureLike<string, classes.DM>Bot:getGroupDMChannelAsync(channelId: string)future.FutureLike<string, classes.GroupDM>Bot:getAnnouncementChannelAsync(channelId: string)future.FutureLike<string, classes.GuildAnnouncement>Bot:getCategoryChannelAsync(channelId: string)future.FutureLike<string, classes.GuildCategory>Bot:getDirectoryChannelAsync(channelId: string)future.FutureLike<string, classes.GuildDirectory>Bot:getStageVCChannelAsync(channelId: string)future.FutureLike<string, classes.GuildStageVoice>Bot:getTextChannelAsync(channelId: string)future.FutureLike<string, classes.GuildText>Bot:getForumChannelAsync(channelId: string)future.FutureLike<string, classes.ThreadForum>Bot:getMediaChannelAsync(channelId: string)future.FutureLike<string, classes.ThreadMedia>Bot:getUserAsync(userId: string)future.FutureLike<string, classes.User>Bot:setLogLevel(logLevel: logger.LogLevel)Bot:getVoiceChannelAsync(channelId: string)future.FutureLike<string, classes.GuildVoice>Bot:requestGuildMembersAsync(guildId: apiTypes.Snowflake, params: { query: string?, limit: number, presences: boolean?, userIds: { apiTypes.Snowflake }?, nonce: string?, })future.FutureLike<string, nil>Bot:setPresenceAsync(presence: builders.presenceJSON)future.FutureLike<string, nil>
Bot.state  :: State
Bot.logger  :: Logger
Bot.application  :: Application?
Bot.user  :: User?
Bot.onReady  :: Emitter<number>
Bot.onAllShardsReady  :: Emitter<()>
Bot.onShardDisconnected  :: Emitter<number, string>
Bot.onShardReconnected  :: Emitter<number>
Bot.onMessage  :: Emitter<Message>
Bot.onMessageChanged  :: Emitter<Message>
Bot.onMessageDeleted  :: Emitter<Snowflake, Snowflake, Snowflake? }>
Bot.onGroupDMChannelCreate  :: Emitter<GroupDM>
Bot.onCategoryChannelCreate  :: Emitter<GuildCategory>
Bot.onAnnouncementChannelCreate  :: Emitter<GuildAnnouncement>
Bot.onDirectoryChannelCreate  :: Emitter<GuildDirectory>
Bot.onDMChannelCreate  :: Emitter<DM>
Bot.onTextChannelCreate  :: Emitter<GuildText>
Bot.onVoiceChannelCreate  :: Emitter<GuildVoice>
Bot.onStageVoiceChannelCreate  :: Emitter<GuildStageVoice>
Bot.onGroupDMChannelUpdated  :: Emitter<GroupDM>
Bot.onCategoryChannelUpdated  :: Emitter<GuildCategory>
Bot.onAnnouncementChannelUpdated  :: Emitter<GuildAnnouncement>
Bot.onDirectoryChannelUpdated  :: Emitter<GuildDirectory>
Bot.onDMChannelUpdated  :: Emitter<DM>
Bot.onTextChannelUpdated  :: Emitter<GuildText>
Bot.onVoiceChannelUpdated  :: Emitter<GuildVoice>
Bot.onStageVoiceChannelUpdated  :: Emitter<GuildStageVoice>
Bot.onGroupDMChannelDeleted  :: Emitter<GroupDM>
Bot.onCategoryChannelDeleted  :: Emitter<GuildCategory>
Bot.onAnnouncementChannelDeleted  :: Emitter<GuildAnnouncement>
Bot.onDirectoryChannelDeleted  :: Emitter<GuildDirectory>
Bot.onDMChannelDeleted  :: Emitter<DM>
Bot.onTextChannelDeleted  :: Emitter<GuildText>
Bot.onVoiceChannelDeleted  :: Emitter<GuildVoice>
Bot.onStageVoiceChannelDeleted  :: Emitter<GuildStageVoice>
Bot.onUserUpdated  :: Emitter<User>
Bot.onChannelPinsUpdate  :: Emitter<{ guildId: string, channelId: string, DateTime? }>
Bot.onGuildCreate  :: Emitter<Guild>
Bot.onGuildUpdate  :: Emitter<Guild>
Bot.onGuildDelete  :: Emitter<UnavailableGuild>
Bot.onGuildMemberBanned  :: Emitter<{ guildId: string, User }>
Bot.onGuildMemberUnbanned  :: Emitter<{ guildId: string, User }>
Bot.onGuildMemberJoined  :: Emitter<{ guildId: string, GuildMember }>
Bot.onGuildMemberLeft  :: Emitter<{ guildId: string, User }>
Bot.onGuildMemberUpdated  :: Emitter<DateTime?,}>
Bot.onPingInteraction  :: Emitter<Ping>
Bot.onCommandInteraction  :: Emitter<TypesCommand>
Bot.onComponentInteraction  :: Emitter<Component>
Bot.onAutocompleteInteraction  :: Emitter<Autocomplete>
Bot.onModalInteraction  :: Emitter<Modal>
Bot.onMessageReactionRemoveAll  :: Emitter<{ channelId: string, messageId: string, guildId: string? }>
Bot.onMessageReactionRemoveEmoji  :: Emitter<{ channelId: string, messageId: string, guildId: string?, Emoji }>
Bot.onThreadMemberUpdate  :: Emitter<{ guildId: string, ThreadMember }>
Bot.onEntitlementCreate  :: Emitter<Entitlement>
Bot.onEntitlementUpdate  :: Emitter<Entitlement>
Bot.onEntitlementDelete  :: Emitter<Entitlement>
Bot.onGuildAuditLogEntryCreate  :: Emitter<AuditLogEntry>
Bot.onGuildEmojisUpdate  :: Emitter<{ guildId: string, Emoji } }>
Bot.onGuildStickersUpdate  :: Emitter<{ guildId: string, Sticker } }>
Bot.onGuildScheduledEventCreate  :: Emitter<ScheduledEvent>
Bot.onGuildScheduledEventUpdate  :: Emitter<ScheduledEvent>
Bot.onGuildScheduledEventDelete  :: Emitter<ScheduledEvent>
Bot.onGuildScheduledEventUserAdd  :: Emitter<{ guildScheduledEventId: string, userId: string, guildId: string }>
Bot.onGuildScheduledEventUserRemove  :: Emitter<{ guildScheduledEventId: string, userId: string, guildId: string }>
Bot.onIntegrationCreate  :: Emitter<Integration>
Bot.onIntegrationUpdate  :: Emitter<Integration>
Bot.onAutoModerationRuleCreate  :: Emitter<AutomoderationRule>
Bot.onAutoModerationRuleUpdate  :: Emitter<AutomoderationRule>
Bot.onAutoModerationRuleDelete  :: Emitter<AutomoderationRule>
Bot.onGuildRoleCreate  :: Emitter<Role>
Bot.onGuildRoleUpdate  :: Emitter<Role>
Bot.onGuildRoleDelete  :: Emitter<{ guildId: string, roleId: string }>
Bot.onAnnouncementThreadCreate  :: Emitter<Announcement>
Bot.onPublicThreadCreate  :: Emitter<Public>
Bot.onPrivateThreadCreate  :: Emitter<Private>
Bot.onAnnouncementThreadUpdate  :: Emitter<Announcement>
Bot.onPublicThreadUpdate  :: Emitter<Public>
Bot.onPrivateThreadUpdate  :: Emitter<Private>
Bot.onPresenceUpdate  :: Emitter<Presence>
Bot.onGuildIntegrationsUpdate  :: Emitter<{ guildId: string }>
Bot.onWebhooksUpdate  :: Emitter<{ guildId: string, channelId: string }>
Bot.onResumed  :: Emitter<()>
Bot.onVoiceStateUpdate  :: Emitter<VoiceState>
Bot.onStageInstanceCreate  :: Emitter<StageInstance>
Bot.onStageInstanceUpdate  :: Emitter<StageInstance>
Bot.onStageInstanceDelete  :: Emitter<StageInstance>
Bot.onGuildSoundboardSoundCreate  :: Emitter<SoundboardSound>
Bot.onGuildSoundboardSoundUpdate  :: Emitter<SoundboardSound>
Bot.onGuildSoundboardSoundDelete  :: Emitter<{ soundId: string, guildId: string }>
Bot.onGuildSoundboardSoundsUpdate  :: Emitter<{ guildId: string, SoundboardSound } }>

Fired when the gateway rate limits a request. When opcode is RequestGuildMembers, guildId identifies the affected guild.

Bot : queryGatewayInformation ( )  -> FutureLike<string, GetGatewayBotResponse>

Queries the Discord Gateway for bot information.

This function sends a request to the Discord Gateway to retrieve information about the bot, such as the recommended number of shards and session start limit.

Bot : connectAsync ( )  -> FutureLike<string, nil>

Connects the bot to the Discord gateway asynchronously.

This function performs the following steps:

  1. Queries gateway information
  2. Asserts that the query was successful
  3. Connects to the WebSocket using the obtained gateway information

Returns a async that resolves when the connection is established.

Bot : listDefaultSoundboardSoundsAsync ( )  -> FutureLike<string, { SoundboardSound }>

Returns the list of default soundboard sounds available to all guilds.

Bot : getGuildAsync ( guildId withCount )  -> FutureLike<string, Guild>

Returns the classes.guild object for the given id. If with_counts is set to true, this endpoint will also return approximate_member_count and approximate_presence_count for the classes.guild.

Parameters

guildId: string
withCount: boolean?
Bot : getChannelAsync ( channelId )  -> FutureLike<string, Channel>

Returns a channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a channel. The channel type is determined by the generic type parameter T.

Parameters

channelId: string
Bot : getDMChannelAsync ( channelId )  -> FutureLike<string, DM>

Returns a DM channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a DM channel.

Parameters

channelId: string
Bot : getGroupDMChannelAsync ( channelId )  -> FutureLike<string, GroupDM>

Returns a Group DM channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a Group DM channel.

Parameters

channelId: string
Bot : getAnnouncementChannelAsync ( channelId )  -> FutureLike<string, GuildAnnouncement>

Returns an announcement channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about an announcement channel.

Parameters

channelId: string
Bot : getCategoryChannelAsync ( channelId )  -> FutureLike<string, GuildCategory>

Returns a category channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a category channel.

Parameters

channelId: string
Bot : getDirectoryChannelAsync ( channelId )  -> FutureLike<string, GuildDirectory>

Returns a directory channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a directory channel.

Parameters

channelId: string
Bot : getStageVCChannelAsync ( channelId )  -> FutureLike<string, GuildStageVoice>

Returns a stage voice channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a stage voice channel.

Parameters

channelId: string
Bot : getTextChannelAsync ( channelId )  -> FutureLike<string, GuildText>

Returns a text channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a text channel.

Parameters

channelId: string
Bot : getForumChannelAsync ( channelId )  -> FutureLike<string, ThreadForum>

Returns a forum channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a forum channel.

Parameters

channelId: string
Bot : getMediaChannelAsync ( channelId )  -> FutureLike<string, ThreadMedia>

Returns a media channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a media channel.

Parameters

channelId: string
Bot : getUserAsync ( userId )  -> FutureLike<string, User>

Returns a user object for the given user ID.

This function sends a request to the Discord API to retrieve information about a user.

Parameters

userId: string
Bot : setLogLevel ( logLevel )  -> ()

Will set the Log Level for the bot, and all instantiated objects within the bot.

Parameters

logLevel: LogLevel
Bot : getVoiceChannelAsync ( channelId )  -> FutureLike<string, GuildVoice>

Returns a voice channel object for the given channel ID.

This function sends a request to the Discord API to retrieve information about a voice channel.

Parameters

channelId: string
Bot : requestGuildMembersAsync ( guildId params )  -> FutureLike<string, nil>

Requests guild members from the Discord Gateway. Limited to 1 request per guild every 30 seconds when using limit=0 with an empty query. Returns a failed future if the guild is currently rate limited.

Parameters

guildId: Snowflake
params: {
query: string?,
limit: number,
presences: boolean?,
userIds: { apiTypes.Snowflake,
}
Bot : setPresenceAsync ( presence )  -> FutureLike<string, nil>

Allows you to set the presence for the Discord Bot.

Parameters

presence: presenceJSON
Bot . new ( options )  -> ()

Construct a new DiscordLuau object

Parameters

options: {
token: string,
intents: number,
reconnect: boolean?,
logLevel: logger.LogLevel?,
globalRatelimit: number?,
}