Support voice text channel

This commit is contained in:
2022-06-29 18:59:06 +07:00
parent 7d4b3add14
commit 6110dd876e
4 changed files with 17 additions and 9 deletions
+4 -2
View File
@@ -12,7 +12,9 @@ import {
TextChannel, TextChannel,
VoiceBasedChannel, VoiceBasedChannel,
PermissionsBitField, PermissionsBitField,
ButtonStyle ButtonStyle,
BaseGuildTextChannel,
BaseGuildVoiceChannel
} from 'discord.js'; } from 'discord.js';
import { I18n } from 'i18n'; import { I18n } from 'i18n';
@@ -130,7 +132,7 @@ export async function joinVoiceChannelProcedure(
if (!member || !channel || !guild) return; if (!member || !channel || !guild) return;
if (channel instanceof DMChannel) return; if (channel instanceof DMChannel) return;
if (!(channel instanceof TextChannel)) return; if (!(channel instanceof BaseGuildTextChannel || channel instanceof BaseGuildVoiceChannel)) return;
const memberVoiceChannel = member.voice.channel; //isMessage ? member.voice.channel : DiscordProvider.client.guilds.cache.get(guild.id)!.members.cache.get((data as Interaction).user.id)?.voice.channel; const memberVoiceChannel = member.voice.channel; //isMessage ? member.voice.channel : DiscordProvider.client.guilds.cache.get(guild.id)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
if (!memberVoiceChannel) return; if (!memberVoiceChannel) return;
+1 -1
View File
@@ -261,7 +261,7 @@ class Discord {
// Handling mentions // Handling mentions
this.client.on('messageCreate', async (message: Message) => { this.client.on('messageCreate', async (message: Message) => {
// TODO: Handle DMs commands soon // TODO: Handle DMs commands soon
if (!(message.channel instanceof TextChannel)) return; if (!(message.channel instanceof BaseGuildTextChannel || message.channel instanceof BaseGuildVoiceChannel)) return;
if (message.author.bot) return; if (message.author.bot) return;
if (typeof message.guild?.id === 'undefined') return; if (typeof message.guild?.id === 'undefined') return;
+4 -3
View File
@@ -5,7 +5,8 @@ import {
StageChannel, StageChannel,
Guild, Guild,
PermissionsBitField, PermissionsBitField,
BaseGuildVoiceChannel BaseGuildVoiceChannel,
BaseGuildTextChannel
} from 'discord.js'; } from 'discord.js';
import { import {
AudioPlayer, AudioPlayer,
@@ -83,7 +84,7 @@ export enum DiscordMusicPlayerLoopMode {
export class DiscordMusicPlayerInstance { export class DiscordMusicPlayerInstance {
public queue: Queue; public queue: Queue;
public player: AudioPlayer; public player: AudioPlayer;
public textChannel?: TextChannel; public textChannel?: BaseGuildTextChannel | BaseGuildVoiceChannel;
public voiceChannel: VoiceChannel | StageChannel; public voiceChannel: VoiceChannel | StageChannel;
public voiceConnection?: VoiceConnection; public voiceConnection?: VoiceConnection;
public previousTrack?: ValidTracks; public previousTrack?: ValidTracks;
@@ -151,7 +152,7 @@ export class DiscordMusicPlayerInstance {
return true; return true;
} }
public joinVoiceChannel(voiceChannel: VoiceChannel | StageChannel, textChannel?: TextChannel) { public joinVoiceChannel(voiceChannel: VoiceChannel | StageChannel, textChannel?: BaseGuildTextChannel | BaseGuildVoiceChannel) {
const permissions = voiceChannel.permissionsFor(DiscordProvider.client.user!); const permissions = voiceChannel.permissionsFor(DiscordProvider.client.user!);
if (!permissions || !voiceChannel.joinable || !permissions.has(PermissionsBitField.Flags.Connect)) if (!permissions || !voiceChannel.joinable || !permissions.has(PermissionsBitField.Flags.Connect))
+8 -3
View File
@@ -12,7 +12,9 @@ import {
ColorResolvable, ColorResolvable,
Interaction, Interaction,
InteractionReplyOptions, InteractionReplyOptions,
BaseInteraction BaseInteraction,
BaseGuildVoiceChannel,
VoiceChannel
} from 'discord.js'; } from 'discord.js';
import App from '..'; import App from '..';
@@ -130,14 +132,17 @@ export function makeProcessingEmbed(data: EmbedDataPresets) {
} }
export async function sendMessage( export async function sendMessage(
channel: TextChannel | DMChannel | BaseGuildTextChannel | GuildTextBasedChannel | PartialDMChannel, channel: TextChannel | DMChannel | BaseGuildTextChannel | GuildTextBasedChannel | PartialDMChannel | BaseGuildTextChannel | BaseGuildVoiceChannel,
user: User | undefined, user: User | undefined,
options: string | MessagePayload | MessageOptions options: string | MessagePayload | MessageOptions
) { ) {
let message; let message;
try { try {
message = await channel.send(options); if(channel instanceof BaseGuildVoiceChannel)
message = await (channel as VoiceChannel).send(options);
else
message = await channel.send(options);
} catch (error) { } catch (error) {
if (typeof user === 'undefined') { if (typeof user === 'undefined') {
return Logger.error( return Logger.error(