Add storage to Bot, similar to Flask.config
See original GitHub issueSummary
Current way of adding custom vars to Bot instances suck
What is the feature request for?
discord.ext.commands
The Problem
Currently the recommended way to add custom variables/instances/etc to bot is to attach them directly to Bot’s instance. E.g:
import discordpy
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
bot.var1 = "amogus"
bot.var2 = "sus"
Which is kinda bad, coz there is a very high chance to accidentally pick some variable name internally used by Bot, overwrite it and then break things. Plus, even if someone will carefully browse tru docs to avoid it - its not really future-proof (coz var with conflicting name may be randomly introduced in new version of library)
The Ideal Solution
Simply attach one or two SimpleNamespace storages to Bot(). Like, dunno - Bot.config and Bot.data. Or just one empty dict to be used exclusively by whoever writes a bot. Then boom - everyone will be happy
The Current Solution
Currently you have to manually browse documentation for possible name collisions, manually attach vars to Bot’s instance, then pray for nothing to break on library’s update
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Use name mangling. Make a subclass and call your variable
__config
, so that it will never conflict unless discord.py devs have a personal vendetta against you and find out your class name.I have no plans on changing this. The current approach is pretty bog standard Python.