Answer the question
In order to leave comments, you need to log in
How to use a variable from another file?
Hello, I use cogs, I would like to use a variable from the main file in the cogs folder in the voice.py file?
Main file: main.py
@client.event
async def on_ready():
global tdict
tdict = {}
class voice(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
print(tdict) #как использовать эту переменную тут ?
Answer the question
In order to leave comments, you need to log in
The simplest way is to pass the dictionary to the constructor.
class voice(commands.Cog):
#при создании кога передаёшь ему клиента и tdict
def __init__(self, client, t_dict):
self.client = client
self.tdict = t_dict
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
print(self.tdict)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question