Skip to content

Commit 00bfe2b

Browse files
docs: fix errors in the bot example and add intent (#1416)
* Fix errors in the bot example and add intent Added the message content intent, so that the event listener works correctly, and changed the parameter for the message listen from "interactions.Message" to "interactions.api.events.MessageCreate" to fix the event. Signed-off-by: redninja9854 <100790587+redninja9854@users.noreply.github.com> * ci: correct from checks. * Reword comments Reduce confusion when reading the comments Signed-off-by: redninja9854 <100790587+redninja9854@users.noreply.github.com> * ci: correct from checks. * Change message listener comments Changed the comment explaining what message create was to make it clearer. Signed-off-by: redninja9854 <100790587+redninja9854@users.noreply.github.com> * ci: correct from checks. --------- Signed-off-by: redninja9854 <100790587+redninja9854@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 996e43e commit 00bfe2b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

examples/bot.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This code shows a very brief and small example of how to create a bot with our library.
22
# This example does not cover all the features of the library, but it is enough to get you started.
33
# In order to learn more about how to use the library, please head over to our documentation:
4-
# https://interactionspy.readthedocs.io/en/latest/
4+
# https://interactions-py.github.io/interactions.py/
55

66
# The first thing you need to do is import the library.
77
import interactions
@@ -10,7 +10,11 @@
1010
# When you make a bot, we refer to it as the "client."
1111
# The client is the main object that interacts with the Gateway, what talks to Discord.
1212
# The client is also the main object that interacts with the API, what makes requests with Discord.
13-
client = interactions.Client()
13+
# The client can also have "intents" that are what the bot recieves,
14+
# in this case the default ones and message content (a privilaged intent that needs
15+
# to be enabled in the developer portal)
16+
intents = interactions.Intents.DEFAULT | interactions.Intents.MESSAGE_CONTENT
17+
client = interactions.Client(intents=intents)
1418

1519

1620
# With our client established, let's have the library inform us when the client is ready.
@@ -25,18 +29,21 @@ async def on_ready():
2529
print(f"Our latency is {round(client.latency)} ms.")
2630

2731

32+
# We can either pass in the event name or make the function name be the event name.
2833
@interactions.listen("on_message_create")
29-
async def name_this_however_you_want(message: interactions.Message):
34+
async def name_this_however_you_want(message_create: interactions.events.MessageCreate):
3035
# Whenever we specify any other event type that isn't "READY," the function underneath
3136
# the decorator will most likely have an argument required. This argument is the data
3237
# that is being supplied back to us developers, which we call a data model.
3338

3439
# In this example, we're listening to messages being created. This means we can expect
35-
# a "message" argument to be passed to the function, which will be the data model of such.
40+
# a "message_create" argument to be passed to the function, which will contain the
41+
# data model for the message
3642

3743
# We can use the data model to access the data we need.
3844
# Keep in mind that you can only access the message content if your bot has the MESSAGE_CONTENT intent.
3945
# You can find more information on this in the migration section of the quickstart guide.
46+
message: interactions.Message = message_create.message
4047
print(f"We've received a message from {message.author.username}. The message is: {message.content}.")
4148

4249

@@ -66,5 +73,6 @@ async def hello_world(ctx: interactions.SlashContext):
6673
# object on line 13.
6774
# - we are not setting a presence.
6875
# - we are not automatically sharding, and registering the connection under 1 shard.
69-
# - we are using default intents, which are Gateway intents excluding privileged ones.
76+
# - we are using default intents, which are Gateway intents excluding privileged ones
77+
# - and the privilaged message content intent.
7078
client.start("Your token here.")

0 commit comments

Comments
 (0)