Skip to content

Overview

Banner

Commands are actions with parameters (options) users can call to trigger something. For example, you could have a /ban command, with an option of which user to ban.

Command("ban") { interaction in
guard let target = await interaction.getUser(from: "target") else { return }
try await interaction.client.banUserFromGuild(
guildId: (interaction.interaction.guild?.guild_id)!,
userId: target.id,
payload: .init()
).guardSuccess()
try await interaction.respond {
Message {
Text("✅ Banned user!")
}
}
}
.description("Ban a user.")
.addingOptions {
UserOption(name: "target", description: "The target user to ban")
.required()
}
.integrationType(.all, contexts: .all)
.isUsableInDMS(true)

Adding Commands

Add commands by extending your bot’s type with Groups.

extension MyNewBot {
var utilityCommands: Group {
Command("hello") { interaction in
try await interaction.respond(with: "..world")
}
}
}

Then, within your entrypoint file, add it to your bot’s body.

struct MyNewBot: DiscordBotApp {
...
var body: [any BotScene] {
utilityCommands
}
...