TayDex
TayDex
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
Anyways thank you a lot for the help ended a 2:30h search of pure confusion. Although i do wonder if the guild class can technically be Json serialized wouldnt the best fix be discord.js adding a proper type instead of unknown?
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
Okay so as like a summary for anyone who finds this in the future and as a response to you: That is indeed the problem, although the code you have sent still give me an error and I have to type it differently:
//Typescript complains
async function reportServerAmount(c: Client, { guild: string, add: boolean }) { }
//Unless I write it like this:
async function reportServerAmount(c: Client, { guild, add }: {guild: string, add: boolean}) { }
//Typescript complains
async function reportServerAmount(c: Client, { guild: string, add: boolean }) { }
//Unless I write it like this:
async function reportServerAmount(c: Client, { guild, add }: {guild: string, add: boolean}) { }
As I want multiple things of the guild object, I'm now using this approach: :galaxybrain:
client.on("guildCreate", async (guild) => {
await client.shard?.broadcastEval(reportServerAmount, { context: {guild:{name: guild.name, memberCount: guild.memberCount}, add: true}})
})

async function reportServerAmount(c: Client, {guild, add}: {guild: {name: string, memberCount: number}, add: boolean}) {
client.on("guildCreate", async (guild) => {
await client.shard?.broadcastEval(reportServerAmount, { context: {guild:{name: guild.name, memberCount: guild.memberCount}, add: true}})
})

async function reportServerAmount(c: Client, {guild, add}: {guild: {name: string, memberCount: number}, add: boolean}) {
So I guess I have to pass each element individually, maybe someone knows an easier way. Take what I say with a grain of salt, had a break from coding for a few months and just started with sharding, but the above seems to accomplish what I need without erroring.
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
Oh its all starting to make sense now, well its a few things like name, id, member count and maybe a few more, so I didnt want to pass each as its own context/parameter
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
Yeah, thanks for the attempt, my TS also seems to be insufficient, just can't believe I'm the first to get this, couldn't find anything though.
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
So its either Typescript complains about the function or about the use of it in broadcastEval
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
If I change it to:
async function reportServerAmount(c: Client, {guild, add}) {
async function reportServerAmount(c: Client, {guild, add}) {
The error immediately disappears from broadcastEval, but then I get a Binding element 'guild' implicitly has an 'any' type.ts(7031) on the function definition
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
Well it's the result of multiple tries, can't find a way to get broadcastEval to be happy unless I let guild be type unkown
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
client.on("guildCreate", async (guild) => {
await client.shard?.broadcastEval(reportServerAmount, { context: {guild: guild, add: true}})
})
client.on("guildCreate", async (guild) => {
await client.shard?.broadcastEval(reportServerAmount, { context: {guild: guild, add: true}})
})
Comes straight from the guildCreate event
28 replies
DIAdiscord.js - Imagine an app
Created by TayDex on 3/25/2024 in #djs-questions
broadcastEval() and Typescript
Error here:
await client.shard?.broadcastEval(reportServerAmount, { context: {guild: guild, add: add}})
await client.shard?.broadcastEval(reportServerAmount, { context: {guild: guild, add: add}})
Removing types here will cause all the code inside to complain about implicit any type for guild.
async function reportServerAmount(c: Client, {guild, add}: {guild: Guild, add: boolean}) {
async function reportServerAmount(c: Client, {guild, add}: {guild: Guild, add: boolean}) {
28 replies