From fce68e91a0dc8a58ffead61d933d2ded7e32e0f6 Mon Sep 17 00:00:00 2001 From: Hunter2807 <46440327+Hunter2807@users.noreply.github.com> Date: Wed, 1 Sep 2021 00:46:57 +0530 Subject: Rewording botvars.md tag (#1786) * Reword botvar.md Co-authored-by: Steele Farnsworth <32915757+swfarnsworth@users.noreply.github.com> --- bot/resources/tags/bot_var.md | 23 ----------------------- bot/resources/tags/botvar.md | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 bot/resources/tags/bot_var.md create mode 100644 bot/resources/tags/botvar.md diff --git a/bot/resources/tags/bot_var.md b/bot/resources/tags/bot_var.md deleted file mode 100644 index 6833b3cd8..000000000 --- a/bot/resources/tags/bot_var.md +++ /dev/null @@ -1,23 +0,0 @@ -Python allows you to set custom attributes to class instances, like your bot! By adding variables as attributes to your bot you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below: - -```py -bot = commands.Bot(command_prefix="!") -# Set an attribute on our bot -bot.test = "I am accessible everywhere!" - -@bot.command() -async def get(ctx: commands.Context): - """A command to get the current value of `test`.""" - # Send what the test attribute is currently set to - await ctx.send(ctx.bot.test) - -@bot.command() -async def setval(ctx: commands.Context, *, new_text: str): - """A command to set a new value of `test`.""" - # Here we change the attribute to what was specified in new_text - bot.test = new_text -``` - -This all applies to cogs as well! You can set attributes to `self` as you wish. - -*Be sure **not** to overwrite attributes discord.py uses, like `cogs` or `users`. Name your attributes carefully!* diff --git a/bot/resources/tags/botvar.md b/bot/resources/tags/botvar.md new file mode 100644 index 000000000..3db6ae7ac --- /dev/null +++ b/bot/resources/tags/botvar.md @@ -0,0 +1,23 @@ +Python allows you to set custom attributes to most objects, like your bot! By storing things as attributes of the bot object, you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below: + +```py +bot = commands.Bot(command_prefix="!") +# Set an attribute on our bot +bot.test = "I am accessible everywhere!" + +@bot.command() +async def get(ctx: commands.Context): + """A command to get the current value of `test`.""" + # Send what the test attribute is currently set to + await ctx.send(ctx.bot.test) + +@bot.command() +async def setval(ctx: commands.Context, *, new_text: str): + """A command to set a new value of `test`.""" + # Here we change the attribute to what was specified in new_text + bot.test = new_text +``` + +This all applies to cogs as well! You can set attributes to `self` as you wish. + +*Be sure **not** to overwrite attributes discord.py uses, like `cogs` or `users`. Name your attributes carefully!* -- cgit v1.2.3