feat: the bot wasnt using any caching, this should make many operations far faster now
This commit is contained in:
parent
764e8cd620
commit
b8ffd42184
1 changed files with 14 additions and 2 deletions
16
src/main.rs
16
src/main.rs
|
@ -1,13 +1,16 @@
|
|||
pub mod commands;
|
||||
|
||||
use crate::commands::role_adder::tools::on_role_change;
|
||||
use serenity::all::{ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildMemberUpdateEvent, Interaction};
|
||||
use serenity::model::guild::Member;
|
||||
use serenity::all::{
|
||||
ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildId, GuildMemberUpdateEvent, Interaction,
|
||||
};
|
||||
use serenity::{
|
||||
async_trait,
|
||||
client::{Context, EventHandler},
|
||||
gateway::ChunkGuildFilter,
|
||||
model::{
|
||||
gateway::{GatewayIntents, Ready},
|
||||
guild::Member,
|
||||
user::OnlineStatus,
|
||||
},
|
||||
Client,
|
||||
|
@ -24,6 +27,14 @@ struct Handler;
|
|||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
// this caches members of all servers teh bot is in
|
||||
async fn cache_ready(&self, ctx: Context, guilds: Vec<GuildId>) {
|
||||
for guild in guilds {
|
||||
ctx.shard.chunk_guild(guild, Some(500), false, ChunkGuildFilter::None, None);
|
||||
}
|
||||
println!("Cache built successfully!");
|
||||
}
|
||||
|
||||
// handles previously linked accounts joining the server
|
||||
async fn guild_member_addition(&self, ctx: Context, new_member: Member) {
|
||||
let db_lock = {
|
||||
|
@ -281,6 +292,7 @@ async fn main() {
|
|||
// Build our client.
|
||||
let mut client = Client::builder(&config.discord_token, intents)
|
||||
.event_handler(Handler {})
|
||||
.cache_settings(serenity::cache::Settings::default())
|
||||
.await
|
||||
.expect("Error creating client");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue