Skip to content

Commit fd19d67

Browse files
authored
Merge pull request #234 from Pycord-Development/main
prod
2 parents 744a098 + efdfc32 commit fd19d67

File tree

17 files changed

+280
-167
lines changed

17 files changed

+280
-167
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v2
41+
uses: actions/checkout@v3
4242

4343
# Initializes the CodeQL tools for scanning.
4444
- name: Initialize CodeQL

.github/workflows/codespell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
if: github.event.pull_request.user.type != 'Bot' && !contains(github.event.pull_request.labels.*.name, 'skip-ci')
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v2
8+
- uses: actions/checkout@v3
99
- uses: actions/setup-python@v4
1010
with:
1111
python-version: "3.x"

docs/getting-started/creating-your-first-bot.mdx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,33 @@ getting leaked is to store it in `.env` files.
9090

9191
You can store your tokens in `.env` files. This is a simple way to store sensitive information.
9292

93-
1. Create a file with the name `.env`. Just `.env`, with the dot/period at the start.
94-
2. Define the token in the file, like so:
95-
96-
97-
```env title=".env"
98-
TOKEN = [PASTE YOUR TOKEN HERE]
99-
```
100-
101-
for example:
102-
103-
93+
1. Create a file with the name `.env` (only the extension, with a dot/period at the start and without a name before it).
94+
2. Define the token in the `.env` file (replace the example value with your token).
10495
```env title=".env"
10596
TOKEN = NzkyNzE1NDU0MTk2MDg4ODQy.X-hvzA.Ovy4MCQywSkoMRRclStW4xAYK7I
10697
```
107-
3. Install [`python-dotenv`](https://pypi.org/project/python-dotenv/)
98+
3. Install [`python-dotenv`](https://pypi.org/project/python-dotenv/).
10899
```bash
109100
python -m pip install python-dotenv
110101
```
102+
4. Load the token from the `.env` file.
103+
```python
104+
import dotenv
105+
dotenv.load_dotenv()
106+
token = str(os.getenv("TOKEN"))
107+
```
108+
5. Pass your token as parameter when running the bot.
109+
```python
110+
client.run(token)
111+
```
112+
113+
:::tip
111114

112115
If you are using Git to track your bot's changes, you should create a file called `.gitignore` and add
113116
`.env` to it. This stops your `.env` file from getting tracked along with the rest of your code, and
114-
will not be pushed to a remote Git repository. It will stay secure on your local machine.
117+
will not be pushed to a remote Git repository. As a consequence, it will stay secure on your local machine.
118+
119+
:::
115120

116121
## Coding the Basics
117122

@@ -123,7 +128,7 @@ import os # default module
123128
from dotenv import load_dotenv
124129

125130
load_dotenv() # load all the variables from the env file
126-
bot = discord.Bot(debug_guilds=[...])
131+
bot = discord.Bot()
127132

128133
@bot.event
129134
async def on_ready():
@@ -165,14 +170,13 @@ is a module that we will use to load the env file. You installed this with `pip
165170
Next, we load the env file with `load_dotenv()`.
166171

167172
```py
168-
bot = discord.Bot(debug_guilds=[...])
173+
bot = discord.Bot()
169174
```
170175

171176
In this line, we create a new instance of [`discord.Bot`](https://docs.pycord.dev/en/master/api.html#discord.Bot).
172-
In this object, we pass a `debug_guilds` argument, which is a list of guild IDs that the bot's application
173-
commands will appear in. This is beneficial for testing purposes when we are testing a new command
174-
or two and don't want everyone to be able to use it. If debug guilds are not specified, all of the
175-
servers the bot is in will have access to your slash commands.
177+
In this object, we can pass various parameters for configuration purposes, such as `owner_ids`
178+
and [`intents`](https://docs.pycord.dev/en/stable/api.html?highlight=get_message#discord.Intents).
179+
176180

177181

178182
```py

docs/getting-started/more-features.mdx

Lines changed: 116 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ First, you need to ask Discord to send you events. This is done via "Intents". R
2727

2828
Once you understand what intents are, you can enable the events you need, or just use the default ones with `discord.Intents.all()`.
2929

30-
Now that that's done, let's add an event handler for when a user joins the server. We will use the `on_member_join` event. We will send a private message to the user welcoming them to the server.
30+
Now that that's done, let's add an event handler for when a user joins the server. We will use the [`on_member_join` event](https://docs.pycord.dev/en/master/api.html#discord.on_member_join). We will send a private message to the user welcoming them to the server.
3131

3232
```python
3333
@bot.event
@@ -218,16 +218,21 @@ method, you can set a small footer that holds a message. This has `text` and `ic
218218
- Author - With the [`set_author`](https://docs.pycord.dev/en/master/api.html#discord.Embed.set_author)
219219
method, you can set an author for the embed. This is a small text field at the top of the embed. This
220220
includes `name`, `url` and `icon_url` kwargs.
221-
- Thumbnail - With the [`set_thumbnial`](https://docs.pycord.dev/en/master/api.html#discord.Embed.set_thumbnail)
221+
- Thumbnail - With the [`set_thumbnail`](https://docs.pycord.dev/en/master/api.html#discord.Embed.set_thumbnail)
222222
method, you can set a small image to reside at the top-right of the embed. This has a single `url` kwarg.
223223
- Image - With the [`set_image`](https://docs.pycord.dev/en/master/api.html#discord.Embed.set_image)
224224
method, you can set an image to sit at the bottom of an embed. This has a single `url` kwarg.
225225

226-
There are a lot more methods and attributes you can use to configure embeds. Here, we just covered the basics. Also remember that all of these values are not necessary in an embed. An embed may only contain a few of these, for example, only a description, or a title and a description, and so on.
226+
There are a lot more methods and attributes you can use to configure embeds. Here, we just covered the basics. Also, remember that all of these values are not necessary in an embed. An embed may only contain a few of these. For example, only a description, a title and a description, and so on.
227227

228228
### Markdown
229229
Markdown is a type of markup language that's limited in terms of formatting yet simple. Discord allows
230-
for a watered-down version of markdown to be in their messages. This includes:
230+
for a watered-down version of markdown to be in their messages.
231+
232+
#### Text Markdown
233+
234+
Text formatting can be used in messages and in most embed parts,
235+
as explained in the dedicated section below.
231236

232237
<table>
233238
<tr>
@@ -250,34 +255,122 @@ for a watered-down version of markdown to be in their messages. This includes:
250255
</tr>
251256
</table>
252257

253-
Sadly, Discord does not support other types, such as hyperlinks. The only supported places for hyperlinks are
254-
in embeds and messages sent through webhooks.
258+
#### Code Markdown
255259

256-
Adding markdown to your embeds or messages will give your bot the sparkle it needs.
260+
To create a single-line code block without syntax highlight, wrap the text between single backticks.
261+
This code block will only add a dark background to the text.
262+
263+
```
264+
\`print("Hello world!")\`
265+
```
257266

258-
Here is an example for a hyperlink in embeds.
267+
To create a multi-line code block without syntax highlight, wrap the text between triple backticks
268+
on first and last line. This type of code block will encase the code inside a box.
259269

260270
```
261-
[Click here!](https://pycord.dev/)
271+
\`\`\`
272+
message = "Hello world!"
273+
print(message)
274+
\`\`\`
262275
```
263-
Inside the embed, the example above will look like this: [`Click here!`](https://pycord.dev/)
264276

265-
:::caution
266-
267-
Some embed fields, such as the footer, do not support markdown *at all*, including bold and italics.
268-
269-
:::
277+
To create a multi-line block with syntax highlight, add the name of the language you are using right after
278+
the triple backticks on the first line. For example, for Python you can write either "python" or "py".
270279

271-
#### Code Markdown
280+
```
281+
\`\`\`python
282+
message = "Hello world!"
283+
print(message)
284+
\`\`\`
285+
```
272286

273-
For code markdown, you can choose between `Code Text` and `Code Blocks`.
287+
If you want to use syntax highlight for a single line of code, you still have to format it
288+
like a multi-line block but the code must be on a separate line than the triple backticks.
274289

275-
- \`Code Text\`
276-
- \`\`\`
290+
#### Quote Markdown
277291

278-
Code Blocks
279-
\`\`\`
292+
To create a single-line quote block, start the line with `>` followed by a space.
280293

281-
Code Blocks support different programming languages, such as Python.
294+
```
295+
> This is a single-line quote.
296+
```
282297

283-
If you start your Code Block with <code>```python</code>, you can send readable Python code to Discord.
298+
To create a multi-line quote block, write `>>>` followed by a space. All text
299+
from that point onwards will be included in that quote block.
300+
301+
```
302+
>>> This is a
303+
multi-line quote.
304+
```
305+
306+
#### Spoiler Markdown
307+
308+
To hide a spoiler, encase the text between double pipes. The users
309+
will have to click on it before being able to see the text contained in it.
310+
311+
```
312+
||spoiler||
313+
```
314+
315+
#### Link Markdown
316+
317+
Link formatting only works in embeds and messages sent through webhooks,
318+
by using the following syntax:
319+
320+
```
321+
[Pycord](https://pycord.dev/)
322+
```
323+
324+
Inside the supported elements that have just been mentioned,
325+
the example above will look like this: [`Pycord`](https://pycord.dev/)
326+
327+
Outside of them, the link will still be clickable but the formatting will be ignored,
328+
therefore the example above will look similarly to this: `[Pycord](https://pycord.dev/)`
329+
330+
#### Embed Markdown
331+
332+
Adding markdown to your embeds or messages will give your bot the sparkle it needs,
333+
however, markdown is limited inside embeds. Use the following table as a reference
334+
and keep in mind that embed title and filed names will always show in **bold**.
335+
336+
<table>
337+
<thead>
338+
<tr>
339+
<th>Part</th>
340+
<th>Text</th>
341+
<th>Link</th>
342+
</tr>
343+
</thead>
344+
<tbody>
345+
<tr>
346+
<td>Embed Author</td>
347+
<td>No</td>
348+
<td>No</td>
349+
</tr>
350+
<tr>
351+
<td>Embed Title</td>
352+
<td>Yes</td>
353+
<td>No</td>
354+
</tr>
355+
<tr>
356+
<td>Embed Description</td>
357+
<td>Yes</td>
358+
<td>Yes</td>
359+
</tr>
360+
<tr>
361+
<td>Field Name</td>
362+
<td>Yes</td>
363+
<td>No</td>
364+
</tr>
365+
<tr>
366+
<td>Field Value</td>
367+
<td>Yes</td>
368+
<td>Yes</td>
369+
</tr>
370+
<tr>
371+
<td>Embed Footer</td>
372+
<td>No</td>
373+
<td>No</td>
374+
</tr>
375+
</tbody>
376+
</table>

docs/getting-started/rules-and-common-practices.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ Providing a Terms of Service for your bot is optional, though usually a best pra
3737
what they can and cannot do with your service, and makes it easier to settle disputes if someone
3838
disagrees with you.
3939

40-
Read more in Discord's official [Legal Docs](https://discord.com/developers/docs/legal)
40+
Read more in Discord's official [Legal Docs](https://discord.com/developers/docs/legal).
4141

4242
### Developer Policy
4343

4444
We could list almost every rule about using Discord's API here. *Or* we could simply link Discord's
45-
developer policy to make it easier on us. You can find Discord's developer policy
45+
Developer Policy to make it easier on us. You can find Discord's Developer Policy
4646
[here](https://discord.com/developers/docs/policy). This outlines what you can and cannot do with
47-
Discord's developer API. And, don't worry, it's completely readable and understandable.
47+
Discord's Developer API. And, don't worry, it's completely readable and understandable.
4848

4949
## Best Practices
5050

@@ -78,8 +78,8 @@ bot verification, so verifying as soon as possible gives them enough time to ver
7878
reaches the 100 server cap. If a bot is not verified, it cannot grow beyond 100 servers.
7979

8080
It's also a good idea to only apply for the privileged intents that you need. Applying for intents
81-
your bot doesn't use wastes both your time and Discord's time, as your whole verification request
82-
can be denied simply because you applied for an intent you didn't need.
81+
your bot doesn't use wastes both your time and Discord's time, as your privileged intent request
82+
will be denied simply because you applied for an intent you didn't need.
8383

8484
### Subclassing
8585

@@ -106,7 +106,7 @@ the Creating Your First Bot guide.
106106
You always want to back up your bot's data. This includes both its code *and* its databases. This way,
107107
if something tragic happens, such as your host failing a data migration or you breaking your Raspberry
108108
Pi's SD card that held your bot, you'll still have its precious user data. I have a small program for
109-
my bot that uploads its databases to a remote GitHub repository now and then to not lose any data.
109+
my bot that uploads its databases to a remote GitHub repository every now and then to not lose any data.
110110
It may be smarter to find a bit more of a reliable way to do so, though.
111111

112112
Public or private, having a local Git repository connected to a remote one is a good idea for making
@@ -169,7 +169,7 @@ works entirely on files. However, if for some reason you cannot read/write to an
169169
lots of data, SQLite might not be for you.
170170

171171
While SQLite is a part of the Python Standard Library as the `sqlite3` package, we recommend not using it as it is
172-
synchronous and blocking. You should use an asynchronous alternative, such as `aiosqlite`.
172+
synchronous and blocking. You should use an asynchronous alternative, such as [`aiosqlite`](https://pypi.org/project/aiosqlite/).
173173

174174
#### PostgreSQL
175175
PostgreSQL is also based on SQL, but it also has more features than SQLite. It's compliant with the SQL standard,

docs/installation.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,34 @@ You can find instructions for that [here](More/virtual-environments).
1818

1919
To install Pycord, you can use the following command in your terminal:
2020

21-
python3 -m pip install py-cord
21+
pip install py-cord
2222

2323
:::tip
2424
Remember that you need to install `py-cord`, not `pycord`.
25-
Also, the `python3` command varies depending on your installation. It might be `python` or `python3.8` as an example.
25+
Also, the `pip` command varies depending on your installation. For example, it might be `python3 -m pip` on macOS/Linux or `py3 -m pip` on some versions of Windows.
2626
:::
2727

2828
If you need voice support for your bot, you should run:
2929

30-
python3 -m pip install "py-cord[voice]"
30+
pip install "py-cord[voice]"
3131

3232
## Migration
3333

3434
### Updating Pycord
3535

3636
If you are upgrading from a previous version of Pycord, you can use the following command in your terminal to upgrade to the latest version:
3737

38-
python3 -m pip install -U py-cord
38+
pip install -U py-cord
3939

4040
### Migrating from other libraries
4141

4242
If you are migrating from another library, say, `discord.py`, first of all, you need to uninstall it.
4343

44-
python3 -m pip uninstall discord.py
44+
pip uninstall discord.py
4545

4646
Then, you can install Pycord, it's as simple as that!:
4747

48-
python3 -m pip install py-cord
48+
pip install py-cord
4949

5050
:::caution
5151
Uninstalling `discord.py` *after* installing `py-cord` can cause issues. Make sure to uninstall it first!
@@ -61,7 +61,7 @@ The development build comes with cutting edge features and new functionality, bu
6161

6262
To install the development build, you can use the following command in your terminal:
6363

64-
python -m pip install -U git+https://github.com/Pycord-Development/pycord
64+
pip install -U git+https://github.com/Pycord-Development/pycord
6565

6666
:::important
6767
Git is required to install this build. [Learn how you can install Git](./more/git).

docs/interactions/application-commands/context-menus.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ import DiscordComponent, { defaultOptions } from "../../../src/components/Discor
1717
When you right-click a message, you may see an option called "Apps". Hover over it and you can see
1818
commands a bot can run with that message. These are called message commands.
1919

20-
When you right-click a message in the user list, you can once again see an option called "Apps".
20+
When you right-click a user in the user list, you can once again see an option called "Apps".
2121
Hover over it and you can see commands a bot can run with that message. These are called user commands.
2222

2323
Together, these two are called Context Menus or Context Menu Commands. These commands work very much like normal commands, except they take a member or message.
2424

25+
:::note
26+
27+
A bot can have up to 5 global Context Menus of each type.
28+
29+
:::
30+
2531
## User Commands
2632

2733
Creating a user command is very simple.

0 commit comments

Comments
 (0)