tyler
tyler
DIAdiscord.js - Imagine an app
Created by tyler on 9/10/2024 in #djs-voice
Random latency spikes?
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)
3 replies