From 781537bd170bf35687ddd615a16a68adb9a3fb96 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:19:19 +0200 Subject: [PATCH] change this --- src/helpers/channels/update_voice_state.ts | 32 ++++++++++++++++++++++ src/helpers/mod.ts | 3 ++ 2 files changed, 35 insertions(+) create mode 100644 src/helpers/channels/update_voice_state.ts diff --git a/src/helpers/channels/update_voice_state.ts b/src/helpers/channels/update_voice_state.ts new file mode 100644 index 000000000..17ead3140 --- /dev/null +++ b/src/helpers/channels/update_voice_state.ts @@ -0,0 +1,32 @@ +import { rest } from "../../rest/rest.ts"; +import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts"; +import type { + UpdateSelfVoiceState, +} from "../../types/guilds/update_self_voice_state.ts"; +import { endpoints } from "../../util/constants.ts"; +import { hasOwnProperty, snakelize } from "../../util/utils.ts"; + +/** + * Updates the a user's voice state, defaults to the current user + * Caveats: + * - `channel_id` must currently point to a stage channel. + * - User must already have joined `channel_id`. + * - You must have the `MUTE_MEMBERS` permission. But can always suppress yourself. + * - When unsuppressed, non-bot users will have their `request_to_speak_timestamp` set to the current time. Bot users will not. + * - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak. + * - You are able to set `request_to_speak_timestamp` to any present or future time. + * - When suppressed, the user will have their `request_to_speak_timestamp` removed. + */ +export async function updateBotVoiceState( + guildId: bigint, + options: UpdateSelfVoiceState | { userId: bigint } & UpdateOthersVoiceState, +) { + return await rest.runMethod( + "patch", + endpoints.UPDATE_VOICE_STATE( + guildId, + hasOwnProperty(options, "userId") ? options.userId : undefined, + ), + snakelize(options), + ); +} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 903614119..fa610049d 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,6 +13,7 @@ import { getPins } from "./channels/get_pins.ts"; import { isChannelSynced } from "./channels/is_channel_synced.ts"; import { startTyping } from "./channels/start_typing.ts"; import { swapChannels } from "./channels/swap_channels.ts"; +import { updateBotVoiceState } from "./channels/update_voice_state.ts"; import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts"; import { createSlashCommand } from "./commands/create_slash_command.ts"; import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; @@ -258,6 +259,7 @@ export { unbanMember, unpin, unpinMessage, + updateBotVoiceState, upsertSlashCommand, upsertSlashCommands, validDiscoveryTerm, @@ -279,6 +281,7 @@ export let helpers = { isChannelSynced, startTyping, swapChannels, + updateBotVoiceState, // commands createSlashCommand, deleteSlashCommand,