n0ur
n0ur
DIAdiscord.js - Imagine an app
Created by n0ur on 3/26/2024 in #djs-questions
Building an Efficient Bot: Task Automation and Resource Optimizatione
How mb i found channel.messages.cache.get, thx
6 replies
DIAdiscord.js - Imagine an app
Created by n0ur on 3/26/2024 in #djs-questions
Building an Efficient Bot: Task Automation and Resource Optimizatione
So a cache, something like this ?:
class MessageCaching<T> {
private cacheMessage: Map<string, T>;

constructor() {
this.cache = new Map();
}

set(key: string, value: T): void {
this.cache.set(key, value);
}

get(key: string): T | undefined {
return this.cache.get(key);
}

delete(key: string): void {
this.cache.delete(key);
}

clear(): void {
this.cache.clear();
}

has(key: string): boolean {
return this.cache.has(key);
}

size(): number {
return this.cache.size;
}
}

const messageCache = new MessageCaching<number>();

// Set a value
messageCache.set(guildID, 1);

// Retrieve the value
const value = messageCache.get(guildID);
class MessageCaching<T> {
private cacheMessage: Map<string, T>;

constructor() {
this.cache = new Map();
}

set(key: string, value: T): void {
this.cache.set(key, value);
}

get(key: string): T | undefined {
return this.cache.get(key);
}

delete(key: string): void {
this.cache.delete(key);
}

clear(): void {
this.cache.clear();
}

has(key: string): boolean {
return this.cache.has(key);
}

size(): number {
return this.cache.size;
}
}

const messageCache = new MessageCaching<number>();

// Set a value
messageCache.set(guildID, 1);

// Retrieve the value
const value = messageCache.get(guildID);
6 replies
DIAdiscord.js - Imagine an app
Created by n0ur on 3/26/2024 in #djs-questions
Building an Efficient Bot: Task Automation and Resource Optimizatione
Thank you ! 🙂
6 replies
DIAdiscord.js - Imagine an app
Created by n0ur on 3/26/2024 in #djs-questions
Building an Efficient Bot: Task Automation and Resource Optimizatione
Indeed, you've just made me realize that in any case, the MessageCreate event will be emitted I'm going to opt for a cache and store all the messages in it. Then, I'll keep the task that executes every 5 minutes to go through the cache and do what i need
6 replies