@@ -38,17 +38,18 @@ def _check(i: discord.RawInteractionCreateEvent):
38
38
button_id = interaction .button .custom_id
39
39
40
40
# 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.
43
42
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.
44
44
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 ()])
46
46
47
47
# The Discord API doesn't send an event when you press a link button so we can't "receive" that.
48
48
49
- client .run ('You Bot-Token here' )
49
+ client .run ('your Bot-Token here' )
50
50
########################################################################################################################
51
51
52
+
52
53
# Another command where a small embed is sent where you can move the small white ⬜ with the buttons.
53
54
54
55
pointers = []
@@ -62,7 +63,7 @@ def __init__(self, guild: discord.Guild):
62
63
63
64
@property
64
65
def possition_x (self ):
65
- return _possition_x
66
+ return self . _possition_x
66
67
67
68
def set_x (self , x : int ):
68
69
self ._possition_x += x
@@ -117,7 +118,6 @@ def display(x: int, y: int):
117
118
empty_button = discord .Button (style = discord .ButtonStyle .Secondary , label = " " , custom_id = "empty" , disabled = True )
118
119
119
120
120
- @property
121
121
def arrow_button ():
122
122
return discord .Button (style = discord .ButtonStyle .Primary )
123
123
@@ -128,7 +128,7 @@ async def start_game(ctx: commands.Context):
128
128
await ctx .send (embed = discord .Embed (title = "Little Game" ,
129
129
description = display (x = 0 , y = 0 )),
130
130
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 ),
132
132
arrow_button ().set_label ('↓' ).set_custom_id ('down' ).disable_if (pointer .possition_y <= 0 ),
133
133
arrow_button ().set_label ('→' ).set_custom_id ('right' ))
134
134
]
@@ -137,9 +137,13 @@ async def start_game(ctx: commands.Context):
137
137
138
138
@client .event
139
139
async 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 )
140
144
if interaction .button .custom_id == "up" :
141
145
pointer .set_y (1 )
142
- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
146
+ await message .edit (embed = discord .Embed (title = "Little Game" ,
143
147
description = display (x = pointer .possition_x , y = pointer .possition_y )),
144
148
components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ).disable_if (pointer .possition_y >= 9 ), empty_button ),
145
149
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
148
152
)
149
153
elif interaction .button .custom_id == "down" :
150
154
pointer .set_y (- 1 )
151
- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
155
+ await message .edit (embed = discord .Embed (title = "Little Game" ,
152
156
description = display (x = pointer .possition_x , y = pointer .possition_y )),
153
157
components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
154
158
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
157
161
)
158
162
elif interaction .button .custom_id == "right" :
159
163
pointer .set_x (1 )
160
- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
164
+ await message .edit (embed = discord .Embed (title = "Little Game" ,
161
165
description = display (x = pointer .possition_x , y = pointer .possition_y )),
162
166
components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
163
167
discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ),
@@ -166,7 +170,7 @@ async def on_raw_interaction_create(interaction: discord.RawInteractionCreateEve
166
170
)
167
171
elif interaction .button .custom_id == "left" :
168
172
pointer .set_x (- 1 )
169
- await interaction .edit (embed = discord .Embed (title = "Little Game" ,
173
+ await message .edit (embed = discord .Embed (title = "Little Game" ,
170
174
description = display (x = pointer .possition_x , y = pointer .possition_y )),
171
175
components = [discord .ActionRow (empty_button , arrow_button ().set_label ('↑' ).set_custom_id ('up' ), empty_button ),
172
176
discord .ActionRow (arrow_button ().set_label ('←' ).set_custom_id ('left' ).disable_if (pointer .possition_x <= 0 ),
0 commit comments