discord_gleam
The primary module of discord_gleam.
This module contains high-level functions to interact with the Discord API.
But you can always implement stuff yourself using the low-level functions from the rest of the library. \
Functions
pub fn ban_member(
bot: Bot,
guild_id: String,
user_id: String,
reason: String,
) -> Result(Nil, DiscordError)
pub fn bot(
token: String,
client_id: String,
intents: Intents,
) -> Bot
Create a new bot instance.
Example:
import discord_gleam/discord/intents
fn main() {
let bot = discord_gleam.bot("TOKEN", "CLIENT_ID", intents.default()))
}
pub fn create_dm_channel(
bot: Bot,
user_id: String,
) -> Result(Channel, DiscordError)
Create a DM channel with a user.
Returns a channel object, or a DiscordError if it fails.
pub fn delete_message(
bot: Bot,
channel_id: String,
message_id: String,
reason: String,
) -> Result(Nil, DiscordError)
Deletes an message from a channel.
The reason will be what is shown in the audit log.
Example:
import discord_gleam
fn main() {
...
discord_gleam.delete_message(
bot,
"CHANNEL_ID",
"MESSAGE_ID",
"REASON",
)
}
For an full example, see the `examples/delete_message.gleam` file.
pub fn edit_message(
bot: Bot,
channel_id: String,
message_id: String,
content: String,
embeds: List(Embed),
) -> Result(Nil, DiscordError)
Edits an existing message in a channel.
The message must have been sent by the bot itself.
pub fn interaction_reply_message(
interaction: InteractionCreatePacket,
message: String,
ephemeral: Bool,
) -> Result(Nil, DiscordError)
Make a basic text reply to an interaction.
pub fn kick_member(
bot: Bot,
guild_id: String,
user_id: String,
reason: String,
) -> Result(Nil, DiscordError)
Kicks an member from an server.
The reason will be what is shown in the audit log.
Example:
import discord_gleam
fn main() {
...
discord_gleam.kick_member(bot, "GUILD_ID", "USER_ID", "REASON")
}
For an full example, see the `examples/kick.gleam` file.
pub fn register_global_commands(
bot: Bot,
commands: List(SlashCommand),
) -> Nil
Registers a global slash command.
Restarting your client might be required to see the changes. \
pub fn register_guild_commands(
bot: Bot,
guild_id: String,
commands: List(SlashCommand),
) -> Nil
Registers a guild-specific slash command.
Restarting your client might be required to see the changes. \
pub fn reply(
bot: Bot,
channel_id: String,
message_id: String,
message: String,
embeds: List(Embed),
) -> Result(Nil, DiscordError)
Reply to a message in a channel.
Example:
import discord_gleam
fn main() {
...
discord_gleam.reply(bot, "CHANNEL_ID", "MESSAGE_ID", "Hello world!", [])
}
pub fn run(
bot: Bot,
event_handlers: List(fn(Bot, Packet) -> Nil),
) -> Nil
Start the event loop, with a set of event handlers.
Example:
import discord_gleam/discord/intents
import discord_gleam/event_handler
fn main() {
let bot = discord_gleam.bot("TOKEN", "CLIENT_ID", intents.default())
let event_handlers = [handler]
discord_gleam.run(bot, event_handlers)
}
fn handler(bot: bot.Bot, packet: event_handler.Packet) {
case packet {
event_handler.ReadyPacket(ready) -> {
logging.log(logging.Info, "Logged in as " <> ready.d.user.username)
}
_ -> Nil
}
}
pub fn send_direct_message(
bot: Bot,
user_id: String,
message: String,
embeds: List(Embed),
) -> Result(Nil, DiscordError)
Send a direct message to a user.
Same use as send_message
, but use user_id instead of channel_id.
discord_gleam.send_direct_message(bot, "USER_ID", "Hello world!", [])
Note: This will return a DiscordError if the DM channel cant be made
pub fn send_message(
bot: Bot,
channel_id: String,
message: String,
embeds: List(Embed),
) -> Result(MessageSendResponse, DiscordError)
Send a message to a channel.
Example:
import discord_gleam
fn main() {
...
let msg = discord_gleam.send_message(
bot,
"CHANNEL_ID",
"Hello world!",
[] // embeds
)
}
pub fn wipe_global_commands(
bot: Bot,
) -> Result(Nil, DiscordError)
Wipes all the global slash commands for the bot.
Restarting your client might be required to see the changes. \
pub fn wipe_guild_commands(
bot: Bot,
guild_id: String,
) -> Result(Nil, DiscordError)
Wipes all the guild slash commands for the bot.
Restarting your client might be required to see the changes. \