-
Notifications
You must be signed in to change notification settings - Fork 60
Refactor from More Features to Embeds, Events, Markdown #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elitesparkle
wants to merge
21
commits into
Pycord-Development:main
Choose a base branch
from
Elitesparkle:more-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9356cc8
Refactor from More Features to Embeds, Events, Markdown
Elitesparkle 864c32f
Fix end of files
Elitesparkle c300cff
New category + md examples
BobDotCom 9d6a9f8
Merge branch 'main' into more-features
BobDotCom 7490f69
Fix syntax highlight, sections, examples, and some sentences
Elitesparkle 235cfee
Merge branch 'main' into more-features
Elitesparkle 0ffb222
Merge branch 'main' into more-features
Elitesparkle 53e726d
Fix internal link
Elitesparkle db48c64
Fix examples
Elitesparkle 40031e0
Refactor indentation
Elitesparkle c783550
Merge branch 'main' into more-features
Elitesparkle 9e2b07b
Fix multi-line quote example
Elitesparkle 11b0903
Merge branch 'more-features' of https://github.com/Elitesparkle/guide…
Elitesparkle f267fd6
Revert "Fix examples"
Elitesparkle 0627433
Fix examples
Elitesparkle b1182ef
Fix titles and multi-line quote example
Elitesparkle 3f3d143
Remove non-working language names from code block examples
Elitesparkle ccd56bd
Update docs/getting-started/styling-messages/markdown.mdx
BobDotCom fae2951
Update docs/getting-started/styling-messages/markdown.mdx
BobDotCom 884561d
Update docs/getting-started/styling-messages/markdown.mdx
BobDotCom c24a93b
Update default value for inline field in embeds
Elitesparkle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: Events | ||
description: Events used to listen for certain actions and react to them. | ||
--- | ||
|
||
# Events | ||
|
||
## Event Handlers | ||
|
||
Events in Discord are a way to listen for certain actions. For example, if you want to know when a user joins your server so you could send a welcome message, you can use the `on_member_join` event. | ||
|
||
First, you need to ask Discord to send you events. This is done via "Intents". Read up the [Intents](../Popular-Topics/intents) page for more information. | ||
|
||
Once you understand what intents are, you can enable the events you need, or just use the default ones with `discord.Intents.all()`. | ||
|
||
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. | ||
|
||
```python | ||
@bot.event | ||
async def on_member_join(member): | ||
await member.send( | ||
f'Welcome to the server, {member.mention}! Enjoy your stay here.' | ||
) | ||
``` | ||
|
||
We use the [`discord.Bot.event` decorator](https://docs.pycord.dev/en/master/api.html#discord.Bot.event) to add the event handler. | ||
|
||
The `on_member_join` event is called when a user joins the server. The `member` parameter is the user that joined. Different events have different names and parameters. You can find all of them [here](https://docs.pycord.dev/en/master/api.html#discord.Intents). | ||
|
||
So, that's how you add event handlers! | ||
|
||
## Waiting for User Response | ||
|
||
Let's say you want to create a Guess-the-Number game (where the user has to guess a number between 1-10). You need to send a message to a user and wait for them to respond. You can do this with the [`wait_for`](https://docs.pycord.dev/en/master/api.html#discord.Bot.wait_for) method. | ||
|
||
```python | ||
@bot.command() | ||
async def gtn(ctx): | ||
"""A Slash Command to play a Guess-the-Number game.""" | ||
|
||
await ctx.respond('Guess a number between 1 and 10.') | ||
guess = await bot.wait_for('message', check=lambda message: message.author == ctx.author) | ||
|
||
if int(guess.content) == 5: | ||
await ctx.send('You guessed it!') | ||
else: | ||
await ctx.send('Nope, try again.') | ||
``` | ||
|
||
`wait_for` takes one argument, which is the event type. The event type is the name of the event you want to wait for. In this case, it's `message`. It could also be `reaction` to wait for a reaction to be added. | ||
|
||
We pass a keyword argument to `wait_for` called `check`. The function may look complicated if you're a beginner. We pass a `lambda` function, which simplifies the code a bit. | ||
|
||
The lambda function takes one parameter, `message`. When Pycord receives a message, it passes it to the `check` function. If the function returns `True`, the message is returned. If the function returns `False`, the message is ignored and the bot waits for another message. | ||
|
||
Here, we check if the message is from the user that sent the command. We simply use `message.author == ctx.author`. This will check if the author of the message was the person who invoked the command. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"label": "Styling Messages", | ||
"link": { | ||
"type": "generated-index" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.