Random latency spikes?

Is something not optimized in my code? I'm trying to allow two server vcs to connect (by transferring the audio of one to the other) but sometimes it stops working for about 10 seconds then starts up again.
2 Replies
d.js toolkit
d.js toolkit3mo ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
tyler
tylerOP3mo ago
const { Client, GatewayIntentBits } = require("discord.js");
const { joinVoiceChannel , createAudioPlayer, createAudioResource, StreamType, getVoiceConnection } = require('@discordjs/voice');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] });
let host
const name = '2'
client.on("messageCreate", async message => {
if (message.content == '?host ' + name) {
const channel = message.member.voice.channel
host = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false
});
message.reply('Started hosting in the voice channel.');
}
if (message.content.startsWith('?link ') && message.content != '?link ' + + name) {
const channel = message.member.voice.channel
const guest = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false
});
const player = createAudioPlayer();
const receiver = host.receiver;
const speaking = receiver.speaking;
message.reply('Connected ' + name + ' to the voice channel.');
speaking.on('start', (userId) => {
const stream = receiver.subscribe(userId);
const resource = createAudioResource(stream, { inputType: StreamType.Opus });
player.play(resource);
guest.subscribe(player);
})
}
});
client.login(TOKEN)
const { Client, GatewayIntentBits } = require("discord.js");
const { joinVoiceChannel , createAudioPlayer, createAudioResource, StreamType, getVoiceConnection } = require('@discordjs/voice');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] });
let host
const name = '2'
client.on("messageCreate", async message => {
if (message.content == '?host ' + name) {
const channel = message.member.voice.channel
host = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false
});
message.reply('Started hosting in the voice channel.');
}
if (message.content.startsWith('?link ') && message.content != '?link ' + + name) {
const channel = message.member.voice.channel
const guest = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false
});
const player = createAudioPlayer();
const receiver = host.receiver;
const speaking = receiver.speaking;
message.reply('Connected ' + name + ' to the voice channel.');
speaking.on('start', (userId) => {
const stream = receiver.subscribe(userId);
const resource = createAudioResource(stream, { inputType: StreamType.Opus });
player.play(resource);
guest.subscribe(player);
})
}
});
client.login(TOKEN)
Want results from more Discord servers?
Add your server