create custom channel discord implementation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { VoiceChannelsServiceInterface } from "@avocadi/bot-core/entities/channels/voice/voice-channels.service";
|
||||
import { config } from "config";
|
||||
import { ChannelType, type VoiceChannel } from "discord.js";
|
||||
import { ChannelType, type User, type VoiceChannel } from "discord.js";
|
||||
import client from "lib/client";
|
||||
import { logger } from "lib/common-logger";
|
||||
|
||||
@@ -35,13 +35,21 @@ export class VoiceChannelsService
|
||||
}
|
||||
|
||||
async cloneVoiceChannel(
|
||||
user_id: string,
|
||||
channel: VoiceChannel,
|
||||
options?: { name?: string; position?: number },
|
||||
) {
|
||||
const clonedChannel = await channel.clone({
|
||||
name: options?.name,
|
||||
position: options?.position,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: user_id,
|
||||
allow: ["ManageChannels"],
|
||||
},
|
||||
],
|
||||
});
|
||||
logger.info("DONE");
|
||||
return clonedChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,17 @@ export const handleDynamicVoiceChannelCreation = async (
|
||||
return;
|
||||
}
|
||||
|
||||
const member = newState.member;
|
||||
if (!member) {
|
||||
logger.error("Member not found for VoiceStateUpdate event");
|
||||
return;
|
||||
}
|
||||
// New channel is created if user joined one of the specific channels (e.g. "Join to Create") or switched to one of them
|
||||
const newChannel =
|
||||
await dynamicVoiceChannelService.createDynamicVoiceChannel(channel.id);
|
||||
await dynamicVoiceChannelService.createDynamicVoiceChannel(
|
||||
member.id,
|
||||
channel.id,
|
||||
);
|
||||
logger.debug(`Channel found for VoiceStateUpdate event: ${channel.name}`);
|
||||
if (newChannel) {
|
||||
await newState.setChannel(newChannel);
|
||||
|
||||
Reference in New Issue
Block a user