TypeError: setTimeout is not a function using error when using discord-rpc in electron

Hi! I'm trying to use https://github.com/discordjs/RPC#readme, but have gotten stuck at a specific part. When i run my standalone test for my RPC interaction file, my code works properly. (seen below)
import { Client, Subscription, User } from 'discord-rpc';
import { EventEmitter } from 'events';
import { DiscordNotificationType } from './types';

// import dotenv from 'dotenv';
// dotenv.config();



class discordService extends EventEmitter {
private readonly clientId = '';
private readonly clientSecret = '';
private readonly scopes = ['rpc', 'messages.read', 'rpc.notifications.read'];

private client: Client;

public test = ''

constructor() {
super();
this.client = new Client({ transport: 'ipc' });
console.log('DiscordService constructed');
}


private async subscribe() {
this.client.subscribe('NOTIFICATION_CREATE', ({ data }: any) => {
console.log('(sub)New Discord Notification:', data);
});


}

private async listen() {
this.client.on('NOTIFICATION_CREATE', ({ data, ...rest }: DiscordNotificationType) => {
/*
Response example
(on)New Discord Notification: {
channel_id: '1354222328267149373',
message: {
id: '1354792738591346739',
content: 'o',
content_parsed: [ [Object] ],
nick: 'Eleuthia',
timestamp: '2025-03-27T12:22:39.712000+00:00',
tts: false,
mentions: [],
mention_roles: [],
embeds: [],
attachments: [],
author: {
id: '1250111229582643232',
username: 'femboyeleuthia',
discriminator: '0',
global_name: 'Eleuthia',
avatar: '8ff6e5631d4588748ba11b1611d84223',
avatar_decoration_data: null,
bot: false,
flags: 0,
premium_type: 0
},
pinned: false,
type: 0
},
icon_url: 'https://cdn.discordapp.com/avatars/1250111229582643232/8ff6e5631d4588748ba11b1611d84223.webp?size=240',
title: 'Eleuthia',
body: 'o'
}
*/
console.log('(on)New Discord Notification:', JSON.stringify(rest, null, 2));
this.emit('notification', {
type: 'NOTIFICATION_CREATE',
rest
});
});
}

private async login(clientId: string, clientSecret: string) {
await this.client.login({ clientId,
clientSecret,
scopes: this.scopes,
redirectUri: 'http://localhost' });
}

public async start() {
console.log('Starting DiscordService...');
await this.client.on('ready', () => {
console.log('Logged in as', this.client?.application?.name);
console.log('Authed for user', this.client?.user?.username);
this.subscribe()
this.listen()
});

this.client.on('error', (error) => {
console.error('Discord Client Error:', error);
});


this.login(this.clientId, this.clientSecret)
}
}


export default discordService;
import { Client, Subscription, User } from 'discord-rpc';
import { EventEmitter } from 'events';
import { DiscordNotificationType } from './types';

// import dotenv from 'dotenv';
// dotenv.config();



class discordService extends EventEmitter {
private readonly clientId = '';
private readonly clientSecret = '';
private readonly scopes = ['rpc', 'messages.read', 'rpc.notifications.read'];

private client: Client;

public test = ''

constructor() {
super();
this.client = new Client({ transport: 'ipc' });
console.log('DiscordService constructed');
}


private async subscribe() {
this.client.subscribe('NOTIFICATION_CREATE', ({ data }: any) => {
console.log('(sub)New Discord Notification:', data);
});


}

private async listen() {
this.client.on('NOTIFICATION_CREATE', ({ data, ...rest }: DiscordNotificationType) => {
/*
Response example
(on)New Discord Notification: {
channel_id: '1354222328267149373',
message: {
id: '1354792738591346739',
content: 'o',
content_parsed: [ [Object] ],
nick: 'Eleuthia',
timestamp: '2025-03-27T12:22:39.712000+00:00',
tts: false,
mentions: [],
mention_roles: [],
embeds: [],
attachments: [],
author: {
id: '1250111229582643232',
username: 'femboyeleuthia',
discriminator: '0',
global_name: 'Eleuthia',
avatar: '8ff6e5631d4588748ba11b1611d84223',
avatar_decoration_data: null,
bot: false,
flags: 0,
premium_type: 0
},
pinned: false,
type: 0
},
icon_url: 'https://cdn.discordapp.com/avatars/1250111229582643232/8ff6e5631d4588748ba11b1611d84223.webp?size=240',
title: 'Eleuthia',
body: 'o'
}
*/
console.log('(on)New Discord Notification:', JSON.stringify(rest, null, 2));
this.emit('notification', {
type: 'NOTIFICATION_CREATE',
rest
});
});
}

private async login(clientId: string, clientSecret: string) {
await this.client.login({ clientId,
clientSecret,
scopes: this.scopes,
redirectUri: 'http://localhost' });
}

public async start() {
console.log('Starting DiscordService...');
await this.client.on('ready', () => {
console.log('Logged in as', this.client?.application?.name);
console.log('Authed for user', this.client?.user?.username);
this.subscribe()
this.listen()
});

this.client.on('error', (error) => {
console.error('Discord Client Error:', error);
});


this.login(this.clientId, this.clientSecret)
}
}


export default discordService;
However, when I use it in electron by importing it, i get this error: contextisolation for discord-rpc, as i get error: TypeError: setTimeout is not a function at eval (client.js:100:23) Is there some sort of documentation on why an error on this sort happens? And if not, could please i get some assistance in fixing it? tysm in advance
GitHub
GitHub - discordjs/RPC: A simple RPC client for Discord
A simple RPC client for Discord. Contribute to discordjs/RPC development by creating an account on GitHub.
2 Replies
d.js toolkit
d.js toolkit5d 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! - Marked as resolved by OP
hyperiya :3
hyperiya :3OP5d ago
Node Version: v22.13. Full Stack Trace:
Uncaught (in promise) TypeError: setTimeout is not a function
at eval (client.js:100:23)
at new Promise (<anonymous>)
at RPCClient.connect (client.js:98:28)
at RPCClient.login (client.js:137:16)
at discordService.login (DiscordService.ts:68:1)
at discordService.start (DiscordService.ts:78:1)
Uncaught (in promise) TypeError: setTimeout is not a function
at eval (client.js:100:23)
at new Promise (<anonymous>)
at RPCClient.connect (client.js:98:28)
at RPCClient.login (client.js:137:16)
at discordService.login (DiscordService.ts:68:1)
at discordService.start (DiscordService.ts:78:1)
;~; is there a way to use it in electron or am i gonna have to use some weird solution...? solved i decided to do it myself without library

Did you find this page helpful?