File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -83,14 +83,25 @@ export class Player {
8383 player : this . toJSON ( )
8484 } )
8585
86- this . waitEvent = ( event , filter ) =>
87- new Promise ( ( resolve ) => {
86+ this . waitEvent = ( event , filter , timeout = 15000 ) =>
87+ new Promise ( ( resolve , reject ) => {
8888 const handler = ( _ , payload ) => {
8989 if ( ! filter || filter ( payload ) ) {
90- this . connection . off ( event , handler )
90+ clearTimeout ( timeoutId )
91+ this . connection ?. off ( event , handler )
9192 resolve ( payload )
9293 }
9394 }
95+
96+ const timeoutId = setTimeout ( ( ) => {
97+ this . connection ?. off ( event , handler )
98+ reject (
99+ new Error (
100+ `Event ${ event } timed out after ${ timeout } ms for guild ${ this . guildId } `
101+ )
102+ )
103+ } , timeout )
104+
94105 this . connection . on ( event , handler )
95106 } )
96107
You can’t perform that action at this time.
0 commit comments