Events for Voice

How can I do something like the following but for voice?
import { Listener } from '@sapphire/framework';

export class VoiceStateUpdateListener extends Listener {
constructor(context, options) {
super(context, {
...options,
once: false,
event: 'voiceStateUpdate'
});
}

async run(oldState, newState) {
console.log(newState);
}
}
import { Listener } from '@sapphire/framework';

export class VoiceStateUpdateListener extends Listener {
constructor(context, options) {
super(context, {
...options,
once: false,
event: 'voiceStateUpdate'
});
}

async run(oldState, newState) {
console.log(newState);
}
}
5 Replies
Favna
Favna2y ago
wdym "for voice", it's exactly that.
shadowolf
shadowolfOP2y ago
For example when a user joins or leaves a channel. I've got above how to do a text related event I can't find how to do a voice related.
Favna
Favna2y ago
Exactly like you wrote it. You listen to the voiceStateUpdate event. https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-voiceStateUpdate
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Favna
Favna2y ago
Beyond that, you read the old state and new state and diff them accordingly and do what you want to do. But that's discordjs territory, not sapphire.
shadowolf
shadowolfOP2y ago
I don't think it's working because of intents, I've added GUILD_VOICE_STATE but it says it's invalid bitfield flag. Found it needed to find the right intent.
Want results from more Discord servers?
Add your server