#Events dont fire

1 messages · Page 1 of 1 (latest)

brave wind
#

Hello. Trying this out again however I have noticed when you define events in the create bot function (events prop) they work fine however if you define shard events within the gateway the shard events fire but the actual main events do not. Is there something im missing?

#

Some example code:

export const BOT = createBot({
    token: process.env.BOT_TOKEN,
    events,
    intents: Intents.GuildMessages | Intents.Guilds | Intents.MessageContent | Intents.GuildMembers,
  gateway: {
    totalShards: 5,
    token: process.env.BOT_TOKEN,
    intents: Intents.GuildMessages | Intents.Guilds | Intents.MessageContent | Intents.GuildMembers,
    events: {message},
    lastShardId: 4
  }
});
vestal badge
#

can you show your message event?

by-default the createBot bot creates (if you don't specify it) the message event, you do need to call the bot.handlers[whatever the t param says] to send the event to the bot.events

#

this is the default implementation for the message event (source reference)

async (shard, data) => {
  // TRIGGER RAW EVENT
  bot.events.raw?.(data, shard.id)

  if (!data.t) return

  // RUN DISPATCH CHECK
  await bot.events.dispatchRequirements?.(data, shard.id)
  bot.handlers[data.t as keyof ReturnType<typeof createBotGatewayHandlers>]?.(bot, data, shard.id)
}
brave wind
#
export const message: ShardEvents['message'] = async function (
    shardId, payload
) {
    if (payload.t === 'GUILD_MEMBERS_CHUNK') {
        
    }
};
#

Im under the impression thats the only way I can get this gateway event through discordeno?

vestal badge
brave wind
#

There as in where and for what?

#

const members = await BOT.gateway.requestMembers(guildId, {limit: 0, query: ""}) just returns an empty array iirc

vestal badge
brave wind
#

however it fires the event which I pickup all the chunks on

vestal badge
#

one moment that i actually check the code tho

brave wind
#

(BOT in this case is the bot created from the @undone rock/bot lib)

vestal badge
#

can you also send the version you are using?

brave wind
#

Latest iirc

#

hang on

#

"@undone rock/bot": "^19.0.0-next.169e117",

vestal badge
#

the latest is 19.0.0-next.d81b28a

#

if i type it correctly

#

did you enable bot.gateway.cache.requestMembers.enabled ?

#

if you don't the bot.handlers.GUILD_MEMBER_CHUNK will ignore the chunk

#

you can always get whatever discord dispatches by using the handlers

vestal badge
#

else you won't be able to match the chunk to the request

#

it is not documented, we still need to write the documentation, i don't even think it is written anywhere in the jsdoc comments

brave wind
vestal badge
#

so yes, you can set it after the createBot call

brave wind
#

Ok will do all that and let you know how it goes. Thanks for letting me know about the docs as well it was a bit confusing to understand at first

vestal badge
brave wind
#

Okay

When im trying to set the enabled property it also wants me to set the pending property (A collection of RequestMemberRequest keyed by some string ) - do I just set this as empty for now?

    cache: {
        requestMembers: {
            enabled: true
        }
    }
vestal badge
#

also don't forget to set a nonce for the requestMembers

brave wind
#

Yes ok thanks will test it out now 👍

brave wind
#

Forgot to say works great. Thanks for the support

brave wind
#

Im now experiencing a problem within requestMembers where the promise never resolves.

const members = await BOT.gateway.requestMembers(guildId, {limit: 0, query: "", nonce}).catch(console.log)
    return res.json({members: members})
#

incase relevant cache is set as such

cache: {
        requestMembers: {
            enabled: true,
            pending: new Collection()
        }
    }
#

It worked a few times however stopped not long after

vestal badge
# brave wind Im now experiencing a problem within requestMembers where the promise never reso...

mh

could you try stick a breakpoint (if you are using a debugger) or a console.log in the node_modules/@discordeno/bot/dist/(esm|cjs)/handlers/members/GUILD_MEMBER_CHUNK.js (use esm or cjs based on what you are using for imports)? especially logging payload.chunk_count and payload.chunk_index as it could be what is causing the issue
imo, put it right before the if (payload.chunk_count === 1) ...

also: is the nonce unique for each request? if you use the same nonce 2 time and the previous is still collecting the chunks it will result in a endless promise i think (and partially wrong data i think)

brave wind
#

The nonce is unique for each request. I put basic detailed debugging (random console.logs) and it appears the function isnt even fired (put in both cjs/esm cus why not 🙃 )

vestal badge
brave wind
#

No I just provide an empty object for the events property now (on gateway)

vestal badge
#

can you add this raw event?

bot.events.raw = (d, shardId) => {
  console.log(`${shardId} received:`, d)
}
#

(if you have a row event put the console.log in the first line)

#

just to check that the payload is arriving

brave wind
#

Im only getting heartbeats

#

(11)

vestal badge
#

you have the GuildMembers indent, right?

vestal badge
#

oh, i didn't see it before

brave wind
#

(I am recieving other events eg message create)

vestal badge
#

I'm very confused about why you are not receiving the event

brave wind
#

Tell me about it

#

Is there any other events I can try debug on?

vestal badge
#

other than the message shard event itself no, but the event.raw is always called by the default impl of that event for createBot

brave wind
#

Its weird so one of my deployments it works on and another it doesnt

#

fetching members for the same guild, no errors or anything

#

One bot however is verified and another isnt

#

So in the 3 tested

Prod - No
QA/Beta or whatver - Yes
Dev - no

vestal badge
#

I'm assuming all 3 have the same version of discordeno, is that right?

brave wind
#

Yeah

vestal badge
#

I'm trying to read both the code and the discord docs and i seriously don't know that could be

#

wait on what version are you?

brave wind
#

d81b28a

vestal badge
#

the same from before or you updated?

brave wind
#

all 3 currently running on d81b28a

vestal badge
#

can you try overriding bot.gateway.sendPayload to log the data object (param 2) and get shard from the bot.gateway.shards map using the shardId (param 1) as key to send the payload?

#
    async sendPayload(shardId, payload) {
      console.log(payload)
      const shard = gateway.shards.get(shardId)

      if (!shard) {
        throw new Error(`Shard (id: ${shardId} not found`)
      }

      await shard.send(payload)
    }```
#

as at this point might as well check if the shard is sending the message at all

brave wind
#

I have a feeling it isnt but lets see

#

its sending

#

{
op: 8,
d: {
guild_id: '954689707005075486',
query: '',
limit: 0,
presences: false,
user_ids: undefined,
nonce: '7146629314279116800'
}
}

vestal badge
#

then I'm even more confused

brave wind
#

so to summarise so far

sends to discord
discord sends nothing back

#

but I have a feeling its not a discord routed problem

vestal badge
#

and your beta bot works correctly somehow

#

from what i understood

brave wind
#

yes

#

oh this will make you even more confused

#

forgot to mention prod just returns an empty array

vestal badge
#

oh no

brave wind
#

so dev doesnt resolve, beta works as expected and prod just returns an empty array

vestal badge
#

with the same code, same intent same guild but different tokens?

brave wind
#

Yep

vestal badge
#

sorry but I do not know what the F is causing this

brave wind
#

Oh hang on I think I got it working

#

bear with me one moment

#

its definetely a versioning problem

vestal badge
#

define versioning in this context

brave wind
#

scratch that

#

reverse

#

well I fixed it on prod by running npm install

#

however

vestal badge
#

now I'm even more confused

if you already updated the dep, what the f did npm installed that it fixed it?!

vestal badge
brave wind
#

yes

#

im gonna try rollback to the version before I bothered you for the second time on dev and see if that works

vestal badge
brave wind
#

shore

#

doesnt work

#

but im fed up of trying to fix it on dev

#

doesnt rlly matter now my problem is fixed on prod just hope I dont need to touch this code again