mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
fix: add sendStartNotification to stages. Closes #2152
This commit is contained in:
@@ -2,16 +2,24 @@ import type { Bot } from "../../bot.ts";
|
||||
import { DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
/** Creates a new Stage instance associated to a Stage channel. Requires the user to be a moderator of the Stage channel. */
|
||||
export async function createStageInstance(bot: Bot, channelId: bigint, topic: string) {
|
||||
export async function createStageInstance(bot: Bot, options: CreateStageInstance) {
|
||||
const result = await bot.rest.runMethod<DiscordStageInstance>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.STAGE_INSTANCES(),
|
||||
{
|
||||
channel_id: channelId.toString(),
|
||||
topic,
|
||||
channel_id: options.channelId.toString(),
|
||||
topic: options.topic,
|
||||
send_start_notification: options.sendStartNotification,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.stageInstance(bot, result);
|
||||
}
|
||||
|
||||
export interface CreateStageInstance {
|
||||
channelId: bigint;
|
||||
topic: string;
|
||||
/** Notify @everyone that the stage instance has started. Requires the MENTION_EVERYONE permission. */
|
||||
sendStartNotification?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { BotWithCache, PermissionStrings } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export function createStageInstance(bot: BotWithCache) {
|
||||
const createStageInstanceOld = bot.helpers.createStageInstance;
|
||||
|
||||
bot.helpers.createStageInstance = async function (channelId, topic) {
|
||||
if (!bot.utils.validateLength(topic, { max: 120, min: 1 })) {
|
||||
bot.helpers.createStageInstance = async function (options) {
|
||||
if (!bot.utils.validateLength(options.topic, { max: 120, min: 1 })) {
|
||||
throw new Error(
|
||||
"The topic length for creating a stage instance must be between 1-120.",
|
||||
);
|
||||
}
|
||||
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
const perms = new Set<PermissionStrings>([
|
||||
"MANAGE_CHANNELS",
|
||||
"MUTE_MEMBERS",
|
||||
"MOVE_MEMBERS",
|
||||
]);
|
||||
|
||||
if (options.sendStartNotification) {
|
||||
perms.add("MENTION_EVERYONE");
|
||||
}
|
||||
|
||||
return await createStageInstanceOld(channelId, topic);
|
||||
requireBotChannelPermissions(bot, options.channelId, [...perms.values()]);
|
||||
|
||||
return await createStageInstanceOld(options);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user