© 2026 Hedgehog Software, LLC
const { Client, Events, GatewayIntentBits } = require('discord.js'); const { joinVoiceChannel, EndBehaviorType, createAudioPlayer, createAudioResource, entersState, VoiceConnectionStatus } = require('@discordjs/voice'); const { getAudioBuffer } = require('simple-tts-mp3'); const fs = require('fs'); const client = new Client({ intents: [GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); var connection; client.login(token); client.on(Events.MessageCreate, async msg =>{ if (!msg.content.startsWith("m!")) return; msg.content = msg.content.replace('m!', ''); msg.content = msg.content.split(" "); if (msg.content[0] == "join") { if (msg.member.voice.channel) { connection = joinVoiceChannel({ channelId: msg.member.voice.channel.id, guildId: msg.member.voice.channel.guild.id, adapterCreator: msg.guild.voiceAdapterCreator, selfDeaf: false, selfMute: false, }); connection.on('stateChange', (old_state, new_state) => { if (old_state.status === VoiceConnectionStatus.Ready && new_state.status === VoiceConnectionStatus.Connecting) { connection.configureNetworking(); } }); } } else if (msg.content[0] == "speak") { msg.content.shift(); const buffer = await getAudioBuffer(msg.content.join(" "), 'en'); let resource = createAudioResource(buffer); let player = createAudioPlayer(); try { await entersState(connection, VoiceConnectionStatus.Ready, 5000); } catch (error) { return null; } connection.subscribe(player); player.play(resource); } });
@discordjs/[email protected] @discordjs/[email protected] @picovoice/[email protected] [email protected] [email protected] [email protected] [email protected]
Join the Discord to ask follow-up questions and connect with the community
Support server for discord.js, a Node.js module to interact with Discord's apps API.
57,666 Members