@@ -38,17 +38,18 @@ def _check(i: discord.RawInteractionCreateEvent):
3838 button_id = interaction .button .custom_id
3939
4040 # This sends the Discord-API that the interaction has been received and is being "processed"
41- #(if this is not used, and you don't edit the message like below Discord will indicate that the interaction failed).
42- await interaction .defer ()
41+ await interaction .defer () # if this is not used and you also do not edit the message within 3 seconds as described below, Discord will indicate that the interaction has failed.
4342
43+ # If you use interaction.edit instead of interaction.message.edit, you do not have to deffer the interaction if your response does not last longer than 3 seconds.
4444 await interaction .edit (embed = an_embed .add_field (name = 'Choose' , value = f'Your Choose was `{ button_id } `' ),
45- components = [components [0 ].disable_all_buttons (), components [1 ].disable_all_buttons ()])
45+ components = [components [0 ].disable_all_buttons (), components [1 ].disable_all_buttons ()])
4646
4747 # The Discord API doesn't send an event when you press a link button so we can't "receive" that.
4848
49- client .run ('You Bot-Token here' )
49+ client .run ('your Bot-Token here' )
5050########################################################################################################################
5151
52+
5253# Another command where a small embed is sent where you can move the small white ⬜ with the buttons.
5354
5455pointers = []
@@ -62,7 +63,7 @@ def __init__(self, guild: discord.Guild):
6263
6364 @property
6465 def possition_x (self ):
65- return _possition_x
66+ return self . _possition_x
6667
6768 def set_x (self , x : int ):
6869 self ._possition_x += x
@@ -117,7 +118,6 @@ def display(x: int, y: int):
117118empty_button = discord .Button (style = discord .ButtonStyle .Secondary , label = " " , custom_id = "empty" , disabled = True )
118119
119120
120- @property
121121def arrow_button ():
122122 return discord .Button (style = discord .ButtonStyle .Primary )
123123
@@ -128,7 +128,7 @@ async def start_game(ctx: commands.Context):
128128 await ctx .send (embed = discord .Embed (title = "Little Game" ,
129129 description = display (x = 0 , y = 0 )),
130130 components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
131- discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ).disable_if (pointer .possition_x <= 0 ),
131+ discord .ActionRow (arrow_button ().update ( disabled = True ). set_label ('←' ).set_custom_id ('left' ).disable_if (pointer .possition_x <= 0 ),
132132 arrow_button ().set_label ('↓' ).set_custom_id ('down' ).disable_if (pointer .possition_y <= 0 ),
133133 arrow_button ().set_label ('→' ).set_custom_id ('right' ))
134134 ]
@@ -137,9 +137,13 @@ async def start_game(ctx: commands.Context):
137137
138138@client .event
139139async def on_raw_interaction_create (interaction : discord .RawInteractionCreateEvent ):
140+ await interaction .defer ()
141+ pointer : Pointer = get_pointer (interaction .guild )
142+ if not (message := interaction .message ):
143+ message : discord .Message = await interaction .channel .fetch_message (interaction .message_id )
140144 if interaction .button .custom_id == "up" :
141145 pointer .set_y (1 )
142- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
146+ await message .edit (embed = discord .Embed (title = "Little Game" ,
143147 description = display (x = pointer .possition_x , y = pointer .possition_y )),
144148 components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ).disable_if (pointer .possition_y >= 9 ), empty_button ),
145149 discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ).disable_if (pointer .possition_x <= 0 ),
@@ -148,7 +152,7 @@ async def on_raw_interaction_create(interaction: discord.RawInteractionCreateEve
148152 )
149153 elif interaction .button .custom_id == "down" :
150154 pointer .set_y (- 1 )
151- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
155+ await message .edit (embed = discord .Embed (title = "Little Game" ,
152156 description = display (x = pointer .possition_x , y = pointer .possition_y )),
153157 components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
154158 discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ).disable_if (pointer .possition_x <= 0 ),
@@ -157,7 +161,7 @@ async def on_raw_interaction_create(interaction: discord.RawInteractionCreateEve
157161 )
158162 elif interaction .button .custom_id == "right" :
159163 pointer .set_x (1 )
160- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
164+ await message .edit (embed = discord .Embed (title = "Little Game" ,
161165 description = display (x = pointer .possition_x , y = pointer .possition_y )),
162166 components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
163167 discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ),
@@ -166,7 +170,7 @@ async def on_raw_interaction_create(interaction: discord.RawInteractionCreateEve
166170 )
167171 elif interaction .button .custom_id == "left" :
168172 pointer .set_x (- 1 )
169- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
173+ await message .edit (embed = discord .Embed (title = "Little Game" ,
170174 description = display (x = pointer .possition_x , y = pointer .possition_y )),
171175 components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
172176 discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ).disable_if (pointer .possition_x <= 0 ),
0 commit comments