Q
Q
QweRez2021-09-30 07:36:48
Python
QweRez, 2021-09-30 07:36:48

How to make font work outside of def crudconfig?

61553ef3cbe4a929773195.png

import valve.rcon
import discord
from discord.ext import commands
import configparser
import os 


address = ( "213.239.207.78", 33051 )
password = "11223344"

client = commands.Bot(command_prefix = '!')
@client.event

async def on_ready():
    print ('Bot connected')



@client.command() #название роли чувствительно к регистру
async def role(ctx, arg):
    def crudConfig(path):
        config = configparser.ConfigParser()
        config.read(path)
    
    # Меняем значения из конфиг. файла.
        config.set("Settings", "role", f"{arg}")
    
    # Вносим изменения в конфиг. файл.
        with open(path, "w") as config_file:
            config.write(config_file)
 
 
    if __name__ == "__main__":
        path = "settings.ini"
        crudConfig(path)


def crudConfig(path):
    config = configparser.ConfigParser()
    config.read(path)
    global font
    font = config.get("Settings", "font")

@client.command()
@commands.has_role(font)#название роли чувствительно к регистру
async def rcon(ctx):
        with valve.rcon.RCON(address, password) as rcon:
            response = rcon.execute('say negri pidorasi')<img src="https://habrastorage.org/webt/61/55/3e/61553ede3d64b820039136.png" alt="image"/>
            await ctx.send("Успешно")


client.run('')#токен бота дискорд

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-09-30
@QweRez

A global variable must be declared outside the function, in the global namespace. And then inside the function, indicate that it is global.
But it is better to explicitly pass a value to the function and return from the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question