thechickenknight
DIAdiscord.js - Imagine an app
•Created by thechickenknight on 6/29/2023 in #djs-voice
Did not enter state ready within 5000ms
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);
}
});
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]
@discordjs/[email protected]
@discordjs/[email protected]
@picovoice/[email protected]
20 replies