Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const { Player, Queue } = require('discord-player');
- const fs = require('fs');
- const voice = require('elevenlabs-node');
- const Readable = require('stream').Readable;
- const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES"] });
- const player = new Player(client);
- const { createAudioPlayer, createAudioResource, joinVoiceChannel } = require('@discordjs/voice');
- let selectedVoice = 'Biden';
- const apiKey = '';
- client.once('ready', () => {
- console.log('bot is rdy')
- client.user.setActivity('use !voice to select a voice')
- })
- client.on('messageCreate', async message => {
- if (!message.guild) return;
- const availableVoices = ['Elon', 'Obama', 'Biden', 'Trump', 'JoeRogan', 'Drake']
- // Voice selection command
- if (message.content.startsWith('!voice')) {
- const voice = message.content.split(' ')[1];
- if (!voice || !availableVoices.includes(voice)) {
- message.channel.send(`Please provide a voice. Available voices: ${availableVoices.join(', ')}`);
- return;
- }
- selectedVoice = voice;
- message.channel.send(`Voice has been set to ${voice}`);
- }
- // Text-to-speech command
- if (message.content.startsWith('!say')) {
- if (message.member.voice.channel) {
- if (selectedVoice === 'Elon') {
- selectedVoice = 'i99wWXLyaALXuxVzliDw'
- } else if (selectedVoice === 'Biden') {
- selectedVoice = 'lbBNCWP1CKEAn5fM0KkU'
- } else if (selectedVoice === 'Trump') {
- selectedVoice = 'xJ0M9yCnZyvecQuvadOy'
- } else if (selectedVoice === 'Obama') {
- selectedVoice = '4E920yKtoWGA0re2UZ0i'
- } else if (selectedVoice === 'JoeRogan') {
- selectedVoice = 'dv0ogR0UV2wGPmuYeWRQ'
- } else if (selectedVoice === 'Drake') {
- selectedVoice = '17QH5eDZONYqk8DbTRb9'
- }
- const text = message.content.slice(4);
- const fileName = `audio-${Date.now()}.mp3`;
- await voice.textToSpeech(apiKey, selectedVoice, fileName, text);
- const connection = joinVoiceChannel({
- channelId: message.member.voice.channel.id,
- guildId: message.guild.id,
- adapterCreator: message.guild.voiceAdapterCreator,
- });
- const player = createAudioPlayer();
- const resource = createAudioResource(fileName);
- player.play(resource);
- connection.subscribe(player);
- } else {
- message.reply('You need to join a voice channel first!');
- }
- }
- });
- client.login('');
Advertisement
Add Comment
Please, Sign In to add comment