mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 05:51:35 +02:00
Join/Leave Voice Commands
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const path = require('path');
|
||||
const sounds = require('../../assets/json/airhorn');
|
||||
|
||||
module.exports = class AirhornCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'airhorn',
|
||||
group: 'other',
|
||||
memberName: 'airhorn',
|
||||
description: 'Plays an airhorn sound in a voice channel.',
|
||||
guildOnly: true,
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
credit: [
|
||||
{
|
||||
name: 'Discord',
|
||||
url: 'https://discord.com/',
|
||||
reason: 'Airhorn Sounds',
|
||||
reasonURL: 'https://github.com/discord/airhornbot/tree/master/audio'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!voiceChannel) return msg.say('Please enter a voice channel first.');
|
||||
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) {
|
||||
return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.');
|
||||
}
|
||||
if (!voiceChannel.joinable) return msg.say('Your voice channel is not joinable.');
|
||||
if (this.client.voice.connections.has(voiceChannel.guild.id)) return msg.say('I am already playing a sound.');
|
||||
try {
|
||||
const connection = await voiceChannel.join();
|
||||
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
|
||||
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
|
||||
await msg.react('🔉');
|
||||
dispatcher.once('finish', () => voiceChannel.leave());
|
||||
dispatcher.once('error', () => voiceChannel.leave());
|
||||
return null;
|
||||
} catch (err) {
|
||||
voiceChannel.leave();
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -6,7 +6,6 @@ module.exports = class InviteCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'invite',
|
||||
aliases: ['join'],
|
||||
group: 'util',
|
||||
memberName: 'invite',
|
||||
description: 'Responds with the bot\'s invite links.',
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const path = require('path');
|
||||
const sounds = require('../../assets/json/airhorn');
|
||||
|
||||
module.exports = class AirhornCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'airhorn',
|
||||
group: 'voice',
|
||||
memberName: 'airhorn',
|
||||
description: 'Plays an airhorn sound in a voice channel.',
|
||||
guildOnly: true,
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
userPermissions: ['CONNECT', 'SPEAK'],
|
||||
clientPermissions: ['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'],
|
||||
credit: [
|
||||
{
|
||||
name: 'Discord',
|
||||
url: 'https://discord.com/',
|
||||
reason: 'Airhorn Sounds',
|
||||
reasonURL: 'https://github.com/discord/airhornbot/tree/master/audio'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
const inGuild = msg.guild ? undefined : null;
|
||||
const connection = this.client.voice.connections.get(msg.guild.id);
|
||||
if (!connection) {
|
||||
return msg.say(`I am not in a voice channel. Use ${msg.anyUsage('join', inGuild, inGuild)} to fix that!.`);
|
||||
}
|
||||
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
|
||||
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
|
||||
await msg.react('🔉');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -6,7 +6,7 @@ module.exports = class DECTalkCommand extends Command {
|
||||
super(client, {
|
||||
name: 'dec-talk',
|
||||
aliases: ['text-to-speech', 'tts'],
|
||||
group: 'edit-text',
|
||||
group: 'voice',
|
||||
memberName: 'dec-talk',
|
||||
description: 'The world\'s best Text-to-Speech.',
|
||||
guildOnly: true,
|
||||
@@ -47,25 +47,19 @@ module.exports = class DECTalkCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { text }) {
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!voiceChannel) return msg.say('Please enter a voice channel first.');
|
||||
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) {
|
||||
return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.');
|
||||
const inGuild = msg.guild ? undefined : null;
|
||||
const connection = this.client.voice.connections.get(msg.guild.id);
|
||||
if (!connection) {
|
||||
return msg.say(`I am not in a voice channel. Use ${msg.anyUsage('join', inGuild, inGuild)} to fix that!.`);
|
||||
}
|
||||
if (!voiceChannel.joinable) return msg.say('Your voice channel is not joinable.');
|
||||
if (this.client.voice.connections.has(voiceChannel.guild.id)) return msg.say('I am already playing a sound.');
|
||||
try {
|
||||
const connection = await voiceChannel.join();
|
||||
const { url } = await request
|
||||
.get('http://tts.cyzon.us/tts')
|
||||
.query({ text });
|
||||
const dispatcher = connection.play(url);
|
||||
connection.play(url);
|
||||
await msg.react('🔉');
|
||||
dispatcher.once('finish', () => voiceChannel.leave());
|
||||
dispatcher.once('error', () => voiceChannel.leave());
|
||||
return null;
|
||||
} catch (err) {
|
||||
voiceChannel.leave();
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class JoinCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'join',
|
||||
aliases: ['join-voice-channel', 'join-vc', 'join-voice', 'join-channel'],
|
||||
group: 'voice',
|
||||
memberName: 'join',
|
||||
description: 'Joins your voice channel.',
|
||||
guarded: true,
|
||||
userPermissions: ['CONNECT']
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!voiceChannel) return msg.say('Please enter a voice channel first.');
|
||||
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK', 'VIEW_CHANNEL'])) {
|
||||
return msg.say('I am missing the "Connect", "Speak", or "View Channel" permission for this voice channel.');
|
||||
}
|
||||
if (!voiceChannel.joinable) return msg.say('Your voice channel is not joinable.');
|
||||
if (this.client.voice.connections.has(voiceChannel.guild.id)) return msg.say('I am already in a voice channel.');
|
||||
await voiceChannel.join();
|
||||
return msg.reply(`Joined **${voiceChannel.name}**!`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class LeaveCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'leave',
|
||||
aliases: ['leave-voice-channel', 'leave-vc', 'leave-voice', 'leave-channel'],
|
||||
group: 'voice',
|
||||
memberName: 'leave',
|
||||
description: 'Leaves the current voice channel.',
|
||||
guarded: true,
|
||||
userPermissions: ['MOVE_MEMBERS']
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = this.client.voice.connections.get(msg.guild.id);
|
||||
if (!connection) return msg.say('I am not in a voice channel.');
|
||||
connection.channel.leave();
|
||||
return msg.reply(`Left **${connection.channel.name}**...`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user