how to make echobot

I want to write code that, using connection.receiver, will listen to what the user with id 633223783204782090 says and immediately repeat it.
4 Replies
d.js toolkit
d.js toolkit2y ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
LEON
LEONOP2y ago
my attempt:
const { createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const { Client } = require('discord.js');

const client = new Client();

client.on('ready', async() => {
const channel = client.channels.cache.get('1085977431808159744');
const connection = await joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});

const player = createAudioPlayer();
const receiver = connection.receiver;

receiver.speaking.on('start', (userId) => {
console.log(`${userId} - started talking`)

if (userId === '633223783204782090') {
const audioStream = receiver.subscribe(userId);
const resource = createAudioResource(audioStream);

player.play(resource);
connection.subscribe(player);
}
});

receiver.speaking.on('end', (userId) => {
console.log(`${userId} - stopped talking`)

if (userId === '633223783204782090') {
player.stop();
}
});
});
const { createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const { Client } = require('discord.js');

const client = new Client();

client.on('ready', async() => {
const channel = client.channels.cache.get('1085977431808159744');
const connection = await joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});

const player = createAudioPlayer();
const receiver = connection.receiver;

receiver.speaking.on('start', (userId) => {
console.log(`${userId} - started talking`)

if (userId === '633223783204782090') {
const audioStream = receiver.subscribe(userId);
const resource = createAudioResource(audioStream);

player.play(resource);
connection.subscribe(player);
}
});

receiver.speaking.on('end', (userId) => {
console.log(`${userId} - stopped talking`)

if (userId === '633223783204782090') {
player.stop();
}
});
});
LEON
LEONOP2y ago
I'm getting this error
No description
LEON
LEONOP2y ago
and after recording an audio segment. there was no playback.
No description

Did you find this page helpful?