Skip to content

Commit

Permalink
Include embed titles in all tags (#2419)
Browse files Browse the repository at this point in the history
* Add title and remove heading

+ also changed any mentioning of `!tags` command

* Fixed yaml scan errors

+ using tabs instead of spaces
+ enclosed title in `comparison.md` with quotes

* Implement ChrisLovering reviews

+ changed all "Name1 vs. Name2" to "Name1 vs. name2"
+ changed "python discord" to "Python Discord" in titles
+ fix typos
+ reverting hunk for `dotenv.md`
+ changed all title cases to sentence cases

* fix grammar

+ changed "embed" to "embeds"

* remove other ot channels mentioned except ot2

* Fix mistakenly removing a blank line
  • Loading branch information
Ibrahim2750mi committed Feb 27, 2023
1 parent 909fb61 commit 88cc0df
Show file tree
Hide file tree
Showing 84 changed files with 327 additions and 124 deletions.
10 changes: 6 additions & 4 deletions bot/resources/tags/args-kwargs.md
@@ -1,5 +1,7 @@
`*args` and `**kwargs`

---
embed:
title: "The `*args` and `**kwargs` parameters"
---
These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names `args` and `kwargs` are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (`*`). If both are used in a function signature, `*args` **must** appear before `**kwargs`.

**Single asterisk**
Expand All @@ -9,9 +11,9 @@ These special parameters allow functions to take arbitrary amounts of positional
`**kwargs` will ingest an arbitrary amount of **keyword arguments**, and store it in a dictionary. There can be **no** additional parameters **after** `**kwargs` in the parameter list.

**Use cases**
**Decorators** (see `!tags decorators`)
**Decorators** (see `/tag decorators`)
**Inheritance** (overriding methods)
**Future proofing** (in the case of the first two bullet points, if the parameters change, your code won't break)
**Flexibility** (writing functions that behave like `dict()` or `print()`)

*See* `!tags positional-keyword` *for information about positional and keyword arguments*
*See* `/tag positional-keyword` *for information about positional and keyword arguments*
6 changes: 4 additions & 2 deletions bot/resources/tags/async-await.md
@@ -1,5 +1,7 @@
**Concurrency in Python**

---
embed:
title: "Concurrency in Python"
---
Python provides the ability to run multiple tasks and coroutines simultaneously with the use of the `asyncio` library, which is included in the Python standard library.

This works by running these coroutines in an event loop, where the context of the running coroutine switches periodically to allow all other coroutines to run, thus giving the appearance of running at the same time. This is different to using threads or processes in that all code runs in the main process and thread, although it is possible to run coroutines in other threads.
Expand Down
5 changes: 4 additions & 1 deletion bot/resources/tags/blocking.md
@@ -1,4 +1,7 @@
**Why do we need asynchronous programming?**
---
embed:
title: "Asynchronous programming"
---
Imagine that you're coding a Discord bot and every time somebody uses a command, you need to get some information from a database. But there's a catch: the database servers are acting up today and take a whole 10 seconds to respond. If you do **not** use asynchronous methods, your whole bot will stop running until it gets a response from the database. How do you fix this? Asynchronous programming.

**What is asynchronous programming?**
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/botvar.md
@@ -1,3 +1,7 @@
---
embed:
title: "Bot variables"
---
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
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/class.md
@@ -1,5 +1,7 @@
**Classes**

---
embed:
title: "Classes"
---
Classes are used to create objects that have specific behavior.

Every object in python has a class, including `list`s, `dict`ionaries and even numbers. Using a class to group code and data like this is the foundation of Object Oriented Programming. Classes allow you to expose a simple, consistent interface while hiding the more complicated details. This simplifies the rest of your program and makes it easier to separately maintain and debug each component.
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/classmethod.md
@@ -1,3 +1,7 @@
---
embed:
title: "The `@classmethod` decorator"
---
Although most methods are tied to an _object instance_, it can sometimes be useful to create a method that does something with _the class itself_. To achieve this in Python, you can use the `@classmethod` decorator. This is often used to provide alternative constructors for a class.

For example, you may be writing a class that takes some magic token (like an API key) as a constructor argument, but you sometimes read this token from a configuration file. You could make use of a `@classmethod` to create an alternate constructor for when you want to read from the configuration file.
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/codeblock.md
@@ -1,3 +1,7 @@
---
embed:
title: "Formatting code on discord"
---
Here's how to format Python code on Discord:

\`\`\`py
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/comparison.md
@@ -1,5 +1,7 @@
**Assignment vs. Comparison**

---
embed:
title: "Assignment vs comparison`"
---
The assignment operator (`=`) is used to assign variables.
```python
x = 5
Expand Down
5 changes: 4 additions & 1 deletion bot/resources/tags/contribute.md
@@ -1,4 +1,7 @@
**Contribute to Python Discord's Open Source Projects**
---
embed:
title: "Contribute to Python Discord's open source projects"
---
Looking to contribute to Open Source Projects for the first time? Want to add a feature or fix a bug on the bots on this server? We have on-going projects that people can contribute to, even if you've never contributed to open source before!

**Projects to Contribute to**
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/customchecks.md
@@ -1,5 +1,7 @@
**Custom Command Checks in discord.py**

---
embed:
title: "Custom command checks in discord.py"
---
Often you may find the need to use checks that don't exist by default in discord.py. Fortunately, discord.py provides `discord.ext.commands.check` which allows you to create you own checks like this:
```py
from discord.ext.commands import check, Context
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/customcooldown.md
@@ -1,5 +1,7 @@
**Cooldowns in discord.py**

---
embed:
title: "Cooldowns in discord.py"
---
Cooldowns can be used in discord.py to rate-limit. In this example, we're using it in an on_message.

```python
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/customhelp.md
@@ -1,3 +1,5 @@
**Custom help commands in discord.py**

---
embed:
title: "Custom help commands in discord.py"
---
To learn more about how to create custom help commands in discord.py by subclassing the help command, please see [this tutorial](https://gist.github.com/InterStella0/b78488fb28cadf279dfd3164b9f0cf96#embed-minimalhelpcommand) by Stella#2000
6 changes: 4 additions & 2 deletions bot/resources/tags/decorators.md
@@ -1,5 +1,7 @@
**Decorators**

---
embed:
title: "Decorators"
---
A decorator is a function that modifies another function.

Consider the following example of a timer decorator:
Expand Down
7 changes: 5 additions & 2 deletions bot/resources/tags/defaultdict.md
@@ -1,5 +1,7 @@
**[`collections.defaultdict`](https://docs.python.org/3/library/collections.html#collections.defaultdict)**

---
embed:
title: "The `collections.defaultdict` class"
---
The Python `defaultdict` type behaves almost exactly like a regular Python dictionary, but if you try to access or modify a missing key, the `defaultdict` will automatically insert the key and generate a default value for it.
While instantiating a `defaultdict`, we pass in a function that tells it how to create a default value for missing keys.

Expand All @@ -19,3 +21,4 @@ In this example, we've used the `int` class which returns 0 when called like a f
>>> my_dict
defaultdict(<class 'int'>, {'foo': 0, 'bar': 5})
```
Check out the [`docs`](https://docs.python.org/3/library/collections.html#collections.defaultdict) to learn even more!
6 changes: 4 additions & 2 deletions bot/resources/tags/dict-get.md
@@ -1,7 +1,9 @@
---
embed:
title: "The `dict.get` method"
---
Often while using dictionaries in Python, you may run into `KeyErrors`. This error is raised when you try to access a key that isn't present in your dictionary. Python gives you some neat ways to handle them.

**The `dict.get` method**

The [`dict.get`](https://docs.python.org/3/library/stdtypes.html#dict.get) method will return the value for the key if it exists, and None (or a default value that you specify) if the key doesn't exist. Hence it will _never raise_ a KeyError.
```py
>>> my_dict = {"foo": 1, "bar": 2}
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/dictcomps.md
@@ -1,3 +1,7 @@
---
embed:
title: "Dictionary comprehensions"
---
Dictionary comprehensions (*dict comps*) provide a convenient way to make dictionaries, just like list comps:
```py
>>> {word.lower(): len(word) for word in ('I', 'love', 'Python')}
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/docstring.md
@@ -1,3 +1,7 @@
---
embed:
title: "Docstrings"
---
A [`docstring`](https://docs.python.org/3/glossary.html#term-docstring) is a string - always using triple quotes - that's placed at the top of files, classes and functions. A docstring should contain a clear explanation of what it's describing. You can also include descriptions of the subject's parameter(s) and what it returns, as shown below:
```py
def greet(name: str, age: int) -> str:
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/dotenv.md
@@ -1,5 +1,7 @@
**Using .env files in Python**

---
embed:
title: "Using .env files in Python"
---
`.env` (dotenv) files are a type of file commonly used for storing application secrets and variables, for example API tokens and URLs, although they may also be used for storing other configurable values. While they are commonly used for storing secrets, at a high level their purpose is to load environment variables into a program.

Dotenv files are especially suited for storing secrets as they are a key-value store in a file, which can be easily loaded in most programming languages and ignored by version control systems like Git with a single entry in a `.gitignore` file.
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/dunder-methods.md
@@ -1,5 +1,7 @@
**Dunder methods**

---
embed:
title: "Dunder methods"
---
Double-underscore methods, or "dunder" methods, are special methods defined in a class that are invoked implicitly. Like the name suggests, they are prefixed and suffixed with dunders. You've probably already seen some, such as the `__init__` dunder method, also known as the "constructor" of a class, which is implicitly invoked when you instantiate an instance of a class.

When you create a new class, there will be default dunder methods inherited from the `object` class. However, we can override them by redefining these methods within the new class. For example, the default `__init__` method from `object` doesn't take any arguments, so we almost always override that to fit our needs.
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/empty-json.md
@@ -1,3 +1,7 @@
---
embed:
title: "Empty JSON error"
---
When using JSON, you might run into the following error:
```
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/enumerate.md
@@ -1,3 +1,7 @@
---
embed:
title: "The `enumerate` function"
---
Ever find yourself in need of the current iteration number of your `for` loop? You should use **enumerate**! Using `enumerate`, you can turn code that looks like this:
```py
index = 0
Expand Down
3 changes: 1 addition & 2 deletions bot/resources/tags/environments.md
@@ -1,9 +1,8 @@
---
aliases: ["envs"]
embed:
title: "Python Environments"
title: "Python environments"
---

The main purpose of Python [virtual environments](https://docs.Python.org/3/library/venv.html#venv-def) is to create an isolated environment for Python projects. This means that each project can have its own dependencies, such as third party packages installed using pip, regardless of what dependencies every other project has.

To see the current environment in use by Python, you can run:
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/except.md
@@ -1,3 +1,7 @@
---
embed:
title: "Error handling"
---
A key part of the Python philosophy is to ask for forgiveness, not permission. This means that it's okay to write code that may produce an error, as long as you specify how that error should be handled. Code written this way is readable and resilient.
```py
try:
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/exit().md
@@ -1,5 +1,7 @@
**Exiting Programmatically**

---
embed:
title: "Exiting programmatically"
---
If you want to exit your code programmatically, you might think to use the functions `exit()` or `quit()`, however this is bad practice. These functions are constants added by the [`site`](https://docs.python.org/3/library/site.html#module-site) module as a convenient method for exiting the interactive interpreter shell, and should not be used in programs.

You should use either [`SystemExit`](https://docs.python.org/3/library/exceptions.html#SystemExit) or [`sys.exit()`](https://docs.python.org/3/library/sys.html#sys.exit) instead.
Expand Down
2 changes: 2 additions & 0 deletions bot/resources/tags/f-strings.md
@@ -1,5 +1,7 @@
---
aliases: ["fstrings", "fstring", "f-string"]
embed:
title: "Format-strings"
---
Creating a Python string with your variables using the `+` operator can be difficult to write and read. F-strings (*format-strings*) make it easy to insert values into a string. If you put an `f` in front of the first quote, you can then put Python expressions between curly braces in the string.

Expand Down
1 change: 0 additions & 1 deletion bot/resources/tags/faq.md
Expand Up @@ -2,5 +2,4 @@
embed:
title: "Frequently asked questions"
---

As the largest Python community on Discord, we get hundreds of questions every day. Many of these questions have been asked before. We've compiled a list of the most frequently asked questions along with their answers, which can be found on our [FAQ page](https://www.pythondiscord.com/pages/frequently-asked-questions/).
5 changes: 4 additions & 1 deletion bot/resources/tags/floats.md
@@ -1,4 +1,7 @@
**Floating Point Arithmetic**
---
embed:
title: "Floating point arithmetic"
---
You may have noticed that when doing arithmetic with floats in Python you sometimes get strange results, like this:
```python
>>> 0.1 + 0.2
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/foo.md
@@ -1,5 +1,7 @@
**Metasyntactic variables**

---
embed:
title: "Metasyntactic variables"
---
A specific word or set of words identified as a placeholder used in programming. They are used to name entities such as variables, functions, etc, whose exact identity is unimportant and serve only to demonstrate a concept, which is useful for teaching programming.

Common examples include `foobar`, `foo`, `bar`, `baz`, and `qux`.
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/for-else.md
@@ -1,5 +1,7 @@
**for-else**

---
embed:
title: "The for-else block"
---
In Python it's possible to attach an `else` clause to a for loop. The code under the `else` block will be run when the iterable is exhausted (there are no more items to iterate over). Code within the else block will **not** run if the loop is broken out using `break`.

Here's an example of its usage:
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/functions-are-objects.md
@@ -1,5 +1,7 @@
**Calling vs. Referencing functions**

---
embed:
title: "Calling vs. referencing functions"
---
When assigning a new name to a function, storing it in a container, or passing it as an argument, a common mistake made is to call the function. Instead of getting the actual function, you'll get its return value.

In Python you can treat function names just like any other variable. Assume there was a function called `now` that returns the current time. If you did `x = now()`, the current time would be assigned to `x`, but if you did `x = now`, the function `now` itself would be assigned to `x`. `x` and `now` would both equally reference the function.
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/global.md
@@ -1,3 +1,7 @@
---
embed:
title: "Globals"
---
When adding functions or classes to a program, it can be tempting to reference inaccessible variables by declaring them as global. Doing this can result in code that is harder to read, debug and test. Instead of using globals, pass variables or objects as parameters and receive return values.

Instead of writing
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/guilds.md
@@ -1,3 +1,5 @@
**Communities**

---
embed:
title: "Communities"
---
The [communities page](https://pythondiscord.com/pages/resources/communities/) on our website contains a number of communities we have partnered with as well as a [curated list](https://github.com/mhxion/awesome-discord-communities) of other communities relating to programming and technology.
6 changes: 4 additions & 2 deletions bot/resources/tags/identity.md
@@ -1,5 +1,7 @@
**Identity vs. Equality**

---
embed:
title: "Identity vs. equality"
---
Should I be using `is` or `==`?

To check if two objects are equal, use the equality operator (`==`).
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/if-name-main.md
@@ -1,5 +1,7 @@
`if __name__ == '__main__'`

---
embed:
title: "`if __name__ == '__main__'`"
---
This is a statement that is only true if the module (your source code) it appears in is being run directly, as opposed to being imported into another module. When you run your module, the `__name__` special variable is automatically set to the string `'__main__'`. Conversely, when you import that same module into a different one, and run that, `__name__` is instead set to the filename of your module minus the `.py` extension.

**Example**
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/indent.md
@@ -1,5 +1,7 @@
**Indentation**

---
embed:
title: "Indentation"
---
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/inline.md
@@ -1,5 +1,7 @@
**Inline codeblocks**

---
embed:
title: "Inline codeblocks"
---
Inline codeblocks look `like this`. To create them you surround text with single backticks, so \`hello\` would become `hello`.

Note that backticks are not quotes, see [this](https://superuser.com/questions/254076/how-do-i-type-the-tick-and-backtick-characters-on-windows/254077#254077) if you are struggling to find the backtick key.
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/intents.md
@@ -1,5 +1,7 @@
**Using intents in discord.py**

---
embed:
title: "Using intents in discord.py"
---
Intents are a feature of Discord that tells the gateway exactly which events to send your bot. Various features of discord.py rely on having particular intents enabled, further detailed [in its documentation](https://discordpy.readthedocs.io/en/stable/api.html#intents). Since discord.py v2.0.0, it has become **mandatory** for developers to explicitly define the values of these intents in their code.

There are *standard* and *privileged* intents. To use privileged intents like `Presences`, `Server Members`, and `Message Content`, you have to first enable them in the [Discord Developer Portal](https://discord.com/developers/applications). In there, go to the `Bot` page of your application, scroll down to the `Privileged Gateway Intents` section, and enable the privileged intents that you need. Standard intents can be used without any changes in the developer portal.
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/iterate-dict.md
@@ -1,3 +1,7 @@
---
embed:
title: "Iteration over dictionaries"
---
There are two common ways to iterate over a dictionary in Python. To iterate over the keys:
```py
for key in my_dict:
Expand Down
6 changes: 4 additions & 2 deletions bot/resources/tags/kindling-projects.md
@@ -1,3 +1,5 @@
**Kindling Projects**

---
embed:
title: "Kindling Projects"
---
The [Kindling projects page](https://nedbatchelder.com/text/kindling.html) on Ned Batchelder's website contains a list of projects and ideas programmers can tackle to build their skills and knowledge.
4 changes: 4 additions & 0 deletions bot/resources/tags/listcomps.md
@@ -1,3 +1,7 @@
---
embed:
title: "List comprehensions"
---
Do you ever find yourself writing something like this?
```py
>>> squares = []
Expand Down
4 changes: 4 additions & 0 deletions bot/resources/tags/local-file.md
@@ -1,3 +1,7 @@
---
embed:
title: "Sending images in embeds using discord.py"
---
Thanks to discord.py, sending local files as embed images is simple. You have to create an instance of [`discord.File`](https://discordpy.readthedocs.io/en/stable/api.html#discord.File) class:
```py
# When you know the file exact path, you can pass it.
Expand Down

0 comments on commit 88cc0df

Please sign in to comment.