#Events dont fire
1 messages · Page 1 of 1 (latest)
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
}
});
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)
}
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?
if you need the handling of the GUILD_MEMBERS_CHUNK it should be already there
There as in where and for what?
const members = await BOT.gateway.requestMembers(guildId, {limit: 0, query: ""}) just returns an empty array iirc
if you want to handle it yourself yes.
don't remember if it is publish on npm but the latest version of @discordeno/gateway returns the array from bot.gateway.requestMembers
however it fires the event which I pickup all the chunks on
one moment that i actually check the code tho
(BOT in this case is the bot created from the @undone rock/bot lib)
can you also send the version you are using?
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
also, you need to set the nonce
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
I can just set the property after initialisising the bot or do I need to use a transformer?
as long as you set that before sending the op 8 (the guild member request or whatever is it called)
sorry, how is a transformer helpful?
so yes, you can set it after the createBot call
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
you need to check what the library is doing is some situations as we don't have the documentation just yet, and it is a annoying, i don't say it isn't
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
}
}
yes set it as a new collection, it will be populated by the requestMembers method
also don't forget to set a nonce for the requestMembers
Yes ok thanks will test it out now 👍
Forgot to say works great. Thanks for the support
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
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)
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 🙃 )
are you still using your custom message shard event function or the default from createBot ?
No I just provide an empty object for the events property now (on gateway)
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
you have the GuildMembers indent, right?
^
oh, i didn't see it before
(I am recieving other events eg message create)
I'm very confused about why you are not receiving the event
other than the message shard event itself no, but the event.raw is always called by the default impl of that event for createBot
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
I'm assuming all 3 have the same version of discordeno, is that right?
Yeah
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?
d81b28a
the same from before or you updated?
all 3 currently running on d81b28a
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
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'
}
}
then I'm even more confused
so to summarise so far
sends to discord
discord sends nothing back
but I have a feeling its not a discord routed problem
yes
oh this will make you even more confused
forgot to mention prod just returns an empty array
oh no
so dev doesnt resolve, beta works as expected and prod just returns an empty array
with the same code, same intent same guild but different tokens?
Yep
sorry but I do not know what the F is causing this
Oh hang on I think I got it working
bear with me one moment
its definetely a versioning problem
define versioning in this context
now I'm even more confused
if you already updated the dep, what the f did npm installed that it fixed it?!
however the dev is still broken?
yes
im gonna try rollback to the version before I bothered you for the second time on dev and see if that works
at this point, run a rm -r on the node modules and reinstall them since at this point I don't f know anymore