mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 10:02:05 +02:00
New voice system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { joinVoiceChannel, getVoiceConnection } = require('@discordjs/voice');
|
||||
const { joinVoiceChannel } = require('@discordjs/voice');
|
||||
const Dispatcher = require('../../structures/Dispatcher');
|
||||
|
||||
module.exports = class JoinCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -22,7 +23,7 @@ module.exports = class JoinCommand extends Command {
|
||||
return msg.reply('I\'m missing the "Connect", "Speak", or "View Channel" permission for this channel.');
|
||||
}
|
||||
if (!voiceChannel.joinable) return msg.reply('Your voice channel is not joinable.');
|
||||
if (getVoiceConnection(voiceChannel.guild.id)) {
|
||||
if (this.client.dispatchers.has(msg.guild.id)) {
|
||||
return msg.reply('I am already in a voice channel.');
|
||||
}
|
||||
joinVoiceChannel({
|
||||
@@ -30,6 +31,7 @@ module.exports = class JoinCommand extends Command {
|
||||
guildId: voiceChannel.guild.id,
|
||||
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
|
||||
});
|
||||
this.client.dispatchers.set(msg.guild.id, new Dispatcher(voiceChannel));
|
||||
return msg.reply(`Joined **${voiceChannel.name}**!`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { getVoiceConnection } = require('@discordjs/voice');
|
||||
|
||||
module.exports = class LeaveCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -15,13 +14,13 @@ module.exports = class LeaveCommand extends Command {
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = getVoiceConnection(msg.guild.id);
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (this.client.dispatchers.has(msg.guild.id)) {
|
||||
if (!connection.canPlay) {
|
||||
const usage = this.client.registry.commands.get('stop').usage();
|
||||
return msg.reply(`I am currently playing audio in this server. Please use ${usage} first.`);
|
||||
}
|
||||
connection.destroy();
|
||||
return msg.reply('No more words out of me...');
|
||||
connection.leave();
|
||||
return msg.reply(`Left **${connection.channel.name}**...`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { getVoiceConnection } = require('@discordjs/voice');
|
||||
|
||||
module.exports = class PauseCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -15,12 +14,12 @@ module.exports = class PauseCommand extends Command {
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = getVoiceConnection(msg.guild.id);
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (!this.client.dispatchers.has(msg.guild.id)) {
|
||||
return msg.reply(`I am not currently playing audio in this server.`);
|
||||
if (connection.canPlay) {
|
||||
return msg.reply('I am not currently playing audio in this server.');
|
||||
}
|
||||
this.client.dispatchers.get(msg.guild.id).pause();
|
||||
connection.pause();
|
||||
return msg.reply('Paused playing.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { getVoiceConnection } = require('@discordjs/voice');
|
||||
|
||||
module.exports = class ResumeCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -15,12 +14,12 @@ module.exports = class ResumeCommand extends Command {
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = getVoiceConnection(msg.guild.id);
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (!this.client.dispatchers.has(msg.guild.id)) {
|
||||
return msg.reply(`I am not currently playing audio in this server.`);
|
||||
if (connection.canPlay) {
|
||||
return msg.reply('I am not currently playing audio in this server.');
|
||||
}
|
||||
this.client.dispatchers.get(msg.guild.id).unpause();
|
||||
connection.unpause();
|
||||
return msg.reply('Resumed playing.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { getVoiceConnection } = require('@discordjs/voice');
|
||||
|
||||
module.exports = class StopCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -15,13 +14,12 @@ module.exports = class StopCommand extends Command {
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = getVoiceConnection(msg.guild.id);
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (!this.client.dispatchers.has(msg.guild.id)) {
|
||||
return msg.reply(`I am not currently playing audio in this server.`);
|
||||
if (connection.canPlay) {
|
||||
return msg.reply('I am not currently playing audio in this server.');
|
||||
}
|
||||
this.client.dispatchers.get(msg.guild.id).stop();
|
||||
this.client.dispatchers.delete(msg.guild.id);
|
||||
connection.stop();
|
||||
return msg.reply('Stopped playing.');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user