#how to tell if a guild is cached?

1 messages · Page 1 of 1 (latest)

full bobcat
#

so, right now, im constantly using fetch_guild and fetch_channel, but i want to use get guild in my init methods for my exts..idk how to tell if it is cached or if its not cached

wintry ridgeBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

eager gazelle
#

Get guild returns None -> not cached

full bobcat
#

and in like an on_ready event, then check if its cached or not

eager gazelle
#

btw why you need to use get_guild instead of fetch?

full bobcat
eager gazelle
#

oh so you cant use async?

#

then I advise you to use Startup event instead of init

#

that's what I do

full bobcat
#

alright

#

something like:

from interactions import Client, Extension, events, listen

class InteractionExtTemplate(Extension):
    def __init__(self, client: Client):
        self.client = client
        
        self.guildObject = None
    @listen() 
    async def on_startup(self, event: events.Startup):
        self.guildObject = self.client.fetch_guild()
    @listen()
    async def onGuildMemberJoin(self, event: events.MemberAdd):
        print("Do your thing with guildObject here...")
        
def setup(client):
    InteractionExtTemplate(client)

this, what you would do?

eager gazelle
#

yep, you can even remove totally the init since it's useless here

full bobcat
#

oh, alright!

#

oh, but i dont have self.client anymore

eager gazelle
#

uh yes you should have it it's passed by default to an Extension

full bobcat
#

i have bot

#

but not client

eager gazelle
#

weird

#

but yeah checked my code and I always use self.bot anyways

full bobcat
#

theres no autocomplete for it

eager gazelle
#

OH yeah!

full bobcat
#

i think i can do value reassign to give it autocomplete

eager gazelle
#

good catch actually

full bobcat
#
from interactions import Client, Extension, events, listen, Bot

class InteractionExtTemplate(Extension):
    @listen() 
    async def on_startup(self, event: events.Startup):
        self.bot: Client = self.bot
        self.guildObject = self.client.fetch_guild()
    @listen()
    async def onGuildMemberJoin(self, event: events.MemberAdd):
        print("Do your thing with guildObject here...")
        
def setup(client):
    InteractionExtTemplate(client)
eager gazelle
#

no self.bot should have proper auto complete, self.client maybe not

full bobcat
#

self.bot does not have any auto complete

#

self.client doesnt even show up

eager gazelle
#

uh you have a weird interpreter then

#

mine shows up no problem

full bobcat
#

i wonder if its because its a string

#

bot: "Client"

#

im using default python ext

#

pylance, python

#

but reassigning it with Client object, works