Skip to content

Commit

Permalink
wiping slash commands
Browse files Browse the repository at this point in the history
  • Loading branch information
cyteon committed Jul 30, 2024
1 parent 219b611 commit f63750e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/discord_gleam.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ pub fn delete_message(
endpoints.delete_message(bot.token, channel_id, message_id, reason)
}

pub fn wipe_slash_commands(bot: bot.Bot, client_id: String) -> #(String, String) {
endpoints.wipe_slash_commands(bot.token, client_id)
}

pub fn register_commands(
bot: bot.Bot,
client_id: String,
Expand All @@ -69,6 +73,6 @@ pub fn register_commands(
pub fn interaction_reply_message(
interaction: interaction_create.InteractionCreate,
message: String,
) {
) -> #(String, String) {
endpoints.interaction_send_text(interaction, message)
}
36 changes: 36 additions & 0 deletions src/discord_gleam/http/endpoints.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,42 @@ pub fn delete_message(
}
}

pub fn wipe_slash_commands(
token: String,
client_id: String,
) -> #(String, String) {
let request =
request.new_auth_post(
http.Put,
"/applications/" <> client_id <> "/commands",
token,
"{}",
)

case hackney.send(request) {
Ok(resp) -> {
case resp.status {
200 -> {
logging.log(logging.Debug, "Wiped Slash Commands")
#("OK", resp.body)
}
_ -> {
logging.log(logging.Error, "Failed to wipe Slash Commands")
io.debug(resp.body)

#("FAILED", resp.body)
}
}
}
Error(err) -> {
logging.log(logging.Error, "Failed to wipe Slash Commands")
io.debug(err)

#("FAILED", "ERROR")
}
}
}

pub fn register_slash_command(
token: String,
client_id: String,
Expand Down
1 change: 1 addition & 0 deletions test/example_bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn main(token: String, client_id: String) {
],
)

discord_gleam.wipe_slash_commands(bot, client_id)
discord_gleam.register_commands(bot, client_id, [test_cmd])

discord_gleam.run(bot, [event_handler])
Expand Down

0 comments on commit f63750e

Please sign in to comment.