@@ -123,12 +123,13 @@ async def _send(
123123 interaction : discord .Interaction ,
124124 * msgs : str ,
125125 embed : discord .Embed | None = None ,
126+ ephemeral : bool = False
126127 ):
127- await interaction .followup .send (msgs [0 ], embed = embed )
128+ await interaction .followup .send (msgs [0 ], embed = embed , ephemeral = ephemeral )
128129 for msg in msgs [1 :]:
129- await interaction .followup .send (msg )
130+ await interaction .followup .send (msg , ephemeral = ephemeral )
130131
131- async def execute (self , interaction : discord .Interaction , config : dict , ** kwargs ):
132+ async def execute (self , interaction : discord .Interaction , config : dict , ephemeral : bool , ** kwargs ):
132133 cmd = [config ["cmd" ]]
133134 if "args" in config :
134135 cmd .extend ([utils .format_string (a , ** kwargs ) for a in shlex .split (config ["args" ])])
@@ -150,11 +151,11 @@ def run_cmd():
150151 stdout , stderr = await asyncio .to_thread (run_cmd )
151152
152153 except Exception as ex :
153- await self ._send (interaction , str (ex ))
154+ await self ._send (interaction , str (ex ), ephemeral = True )
154155 return
155156
156157 if not stdout :
157- await self ._send (interaction , "Done" )
158+ await self ._send (interaction , "Done" , ephemeral = ephemeral )
158159 return
159160
160161 # split stdout into 2‑K chunks wrapped in code blocks
@@ -173,7 +174,7 @@ def run_cmd():
173174 messages .append (cur )
174175
175176 for m in messages :
176- await self ._send (interaction , m )
177+ await self ._send (interaction , m , ephemeral = ephemeral )
177178
178179 else : # no shell – just fire and forget
179180 try :
@@ -183,14 +184,15 @@ def run_cmd() -> subprocess.Popen:
183184
184185 p = await asyncio .to_thread (run_cmd )
185186 self .processes [psutil .Process (p .pid )] = cmd [0 ]
186- await self ._send (interaction , f"Process with PID { p .pid } started." )
187+ await self ._send (interaction , f"Process with PID { p .pid } started." , ephemeral = ephemeral )
187188 except Exception as ex :
188- await self ._send (interaction , str (ex ))
189+ await self ._send (interaction , str (ex ), ephemeral = True )
189190
190191 async def event (
191192 self ,
192193 interaction : discord .Interaction ,
193194 config : dict ,
195+ ephemeral : bool ,
194196 ** kwargs ,
195197 ) -> list [dict ]:
196198 async def do_send (server : Server ):
@@ -201,16 +203,22 @@ async def do_send(server: Server):
201203 await self ._send (
202204 interaction ,
203205 f"Server { server .name } is { server .status .name } ." ,
206+ ephemeral = True
204207 )
205208 return None
206209 else :
207210 if server .status != Status .SHUTDOWN :
208211 await server .send_to_dcs (config )
209- await self ._send (interaction , f"Event sent to { server .name } ." )
212+ await self ._send (
213+ interaction ,
214+ f"Event sent to { server .name } ." ,
215+ ephemeral = ephemeral
216+ )
210217 else :
211218 await self ._send (
212219 interaction ,
213220 f"Server { server .name } is { server .status .name } ." ,
221+ ephemeral = True
214222 )
215223 return None
216224
@@ -242,6 +250,7 @@ async def exec_slash_command(
242250 ** kwargs : Any
243251 ) -> None :
244252 cfg = self .commands [interaction .command .name ]
253+ ephemeral = cfg .get ("ephemeral" , False )
245254
246255 # remove any missing args
247256 for arg in kwargs .copy ():
@@ -266,15 +275,15 @@ async def exec_slash_command(
266275 data : list [dict ] = []
267276
268277 if "execute" in cfg :
269- await self .execute (interaction , cfg ["execute" ], ** kwargs )
278+ await self .execute (interaction , cfg ["execute" ], ephemeral = ephemeral , ** kwargs )
270279 elif "event" in cfg :
271- data = await self .event (interaction , cfg ["event" ], ** kwargs )
280+ data = await self .event (interaction , cfg ["event" ], ephemeral = ephemeral , ** kwargs )
272281 elif "sequence" in cfg :
273282 for seq in cfg ["sequence" ]:
274283 if "execute" in seq :
275- await self .execute (interaction , seq ["execute" ], ** kwargs )
284+ await self .execute (interaction , seq ["execute" ], ephemeral = ephemeral , ** kwargs )
276285 elif "event" in seq :
277- data .extend (await self .event (interaction , seq ["event" ], ** kwargs ))
286+ data .extend (await self .event (interaction , seq ["event" ], ephemeral = ephemeral , ** kwargs ))
278287
279288 if "report" in cfg :
280289 if len (data ) == 1 :
@@ -283,11 +292,17 @@ async def exec_slash_command(
283292 await self ._send (
284293 interaction ,
285294 f"Can't call commands { interaction .command .name } on multiple servers." ,
295+ ephemeral = True
286296 )
287297 return
288298 report = Report (self .bot , self .plugin_name , cfg ["report" ])
289299 env = await report .render (** kwargs )
290- await self ._send (interaction , env .mention , embed = env .embed )
300+ await self ._send (
301+ interaction ,
302+ env .mention ,
303+ embed = env .embed ,
304+ ephemeral = ephemeral
305+ )
291306 elif data :
292307 if len (data ) > 1 :
293308 embed = discord .Embed (color = discord .Color .blue ())
@@ -298,9 +313,9 @@ async def exec_slash_command(
298313 ret ["server_name" ],
299314 ).strip ()
300315 embed .add_field (name = name or "_ _" , value = ret ["value" ] or "_ _" , inline = False )
301- await self ._send (interaction , embed = embed )
316+ await self ._send (interaction , embed = embed , ephemeral = ephemeral )
302317 else :
303- await self ._send (interaction , data [0 ]["value" ])
318+ await self ._send (interaction , data [0 ]["value" ], ephemeral = ephemeral )
304319
305320 @staticmethod
306321 def annotated_params (params : dict ) -> str :
@@ -332,27 +347,28 @@ def register_commands(self):
332347 for name , cmd in self .locals ["commands" ].items ():
333348 sanitized_name = utils .to_valid_pyfunc_name (name )
334349 try :
350+ ephemeral = cmd .get ("ephemeral" , False )
351+
335352 checks : list = []
336353 if "roles" in cmd :
337354 # noinspection PyUnresolvedReferences
338355 checks .append (utils .cmd_has_roles (roles = cmd ["roles" ]).predicate )
339356
340357 params = cmd .get ("params" , {})
341-
342358 if params :
343359 # keyword‑only params
344360 kw_only = self .annotated_params (params )
345361 kw_as_args = ", " .join (f"{ n } ={ n } " for n in params .keys ())
346362 src = f"""
347363async def __{ sanitized_name } _callback(interaction: discord.Interaction, { kw_only } ):
348- await interaction.response.defer()
364+ await interaction.response.defer(ephemeral= { ephemeral } )
349365 await self.exec_slash_command(interaction, { kw_as_args } )
350366 """
351367 else :
352368 # no options – only interaction
353369 src = f"""
354370async def __{ sanitized_name } _callback(interaction: discord.Interaction):
355- await interaction.response.defer()
371+ await interaction.response.defer(ephemeral= { ephemeral } )
356372 await self.exec_slash_command(interaction)
357373 """
358374
0 commit comments