Encountering Error `TypeError: emitter.getMaxListeners is not a function`

Happens as soon as I run the code. I am using ts-node so I have no idea if this is the reason why.
No description
Solution:
I mean, using ts-node is like a minefield, it doesn't always behave as desired and most of the time it's more efficient to use tsc --watch + node . 😅
Jump to solution
8 Replies
kyra
kyra•10mo ago
Can you share the code, please? Or at very least, the listener's options
Aaron
AaronOP•10mo ago
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';
import { ChannelType, OverwriteType, Snowflake, VoiceState } from 'discord.js';

@ApplyOptions<Listener.Options>({
name: 'voiceStateUpdate',
})
export class VoiceStateUpdate extends Listener {
channels: Set<Snowflake> = new Set<Snowflake>();
async run(old_state: VoiceState, new_state: VoiceState) {
const channel_id = '1201376611786817566';
const category_id = '1201376440332079124';

if (new_state.channelId === channel_id) {
try {
const new_channel = await old_state.guild.channels.create({
name: `${old_state.member?.user.username} | private`,
type: ChannelType.GuildVoice,
parent: category_id,
permissionOverwrites: [
{
allow: ['ManageChannels', 'ManageRoles', 'Connect'],
type: OverwriteType.Member,
id: old_state.member?.id!,
},
{
allow: ['Connect'],
deny: ['ManageChannels', 'ManageRoles'],
type: OverwriteType.Member,
id: old_state.guild.id,
},
],
});

await old_state.setChannel(
new_channel,
'voice channel was created by them',
);

this.channels.add(new_channel.id);
} catch (err) {
this.container.logger.error(err);
}
}

if (
old_state.channel &&
this.channels.has(old_state.channelId!) &&
old_state.channel?.members.size! <= 0
) {
await old_state.channel!.delete('Everyone left the voice channel');
}

return;
}
}
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';
import { ChannelType, OverwriteType, Snowflake, VoiceState } from 'discord.js';

@ApplyOptions<Listener.Options>({
name: 'voiceStateUpdate',
})
export class VoiceStateUpdate extends Listener {
channels: Set<Snowflake> = new Set<Snowflake>();
async run(old_state: VoiceState, new_state: VoiceState) {
const channel_id = '1201376611786817566';
const category_id = '1201376440332079124';

if (new_state.channelId === channel_id) {
try {
const new_channel = await old_state.guild.channels.create({
name: `${old_state.member?.user.username} | private`,
type: ChannelType.GuildVoice,
parent: category_id,
permissionOverwrites: [
{
allow: ['ManageChannels', 'ManageRoles', 'Connect'],
type: OverwriteType.Member,
id: old_state.member?.id!,
},
{
allow: ['Connect'],
deny: ['ManageChannels', 'ManageRoles'],
type: OverwriteType.Member,
id: old_state.guild.id,
},
],
});

await old_state.setChannel(
new_channel,
'voice channel was created by them',
);

this.channels.add(new_channel.id);
} catch (err) {
this.container.logger.error(err);
}
}

if (
old_state.channel &&
this.channels.has(old_state.channelId!) &&
old_state.channel?.members.size! <= 0
) {
await old_state.channel!.delete('Everyone left the voice channel');
}

return;
}
}
kyra
kyra•10mo ago
Are you overriding container.client somewhere?
Aaron
AaronOP•10mo ago
no the error seems to occur when I am using the compiled pieces and not the ts versions
Solution
kyra
kyra•10mo ago
I mean, using ts-node is like a minefield, it doesn't always behave as desired and most of the time it's more efficient to use tsc --watch + node . 😅
Aaron
AaronOP•10mo ago
Gotcha, I mean I changed where the pieces are loaded to src and it works for now so ima just put that off as a ts-node bug
Spinel
Spinel•10mo ago
TL;DR: Do not use ts-node, use tsc-watch instead. We very strongly discourage using ts-node because it was never meant to be used for bots. ts-node is designed for REPL purposes. That's short for Read Eval Print Loop. Which means to read some code, dump it in an eval() statement, print the result, and loop. A discord bot is not that. A Discord bot sets up a permanent web socket connection to the Discord server and connects to the rest gateway. There is read yes, but no eval, no print, and no loop. So what should you use instead? The most ideal way is to just use the watch flag of tsc (tsc --watch) and run node dist/index.js to run your bot, then cancel that process and restart it when you have changes that require restarting. You would open 2 terminal tabs, 1 in which you run tsc --watch and another in which you run the bot. This is, in particular, the most ideal way, because Discord has a limit to the amount of times you can log in with your bot, or register commands, per day. Constantly logging in over and over again due to an auto-restarting process will get you close to that limit very quickly and once you exceed it, your development will be halted entirely for the current day. However, this can be quite tedious so a great package to use instead is tsc-watch.
Favna
Favna•10mo ago
I'm gonna hazzard a guess, ts-node does not load .d.ts file automatically. Possibly related. Why for god's sake they don't no one knows
Want results from more Discord servers?
Add your server