Search code examples
pythondiscordbotspycord

Unable to send ephemeral ("hidden") message with pycord


According to other answers the following code should send an ephemeral message:
await ctx.send('Message Sent ✅', ephemeral=True)
But when running the code, I get this error:

Ignoring exception in command message:
Traceback (most recent call last):
  File "/home/runner/bot/venv/lib/python3.8/site-packages/discord/commands/core.py", line 126, in wrapped
    ret = await coro(arg)
  File "/home/runner/bot/venv/lib/python3.8/site-packages/discord/commands/core.py", line 860, in _invoke
    await self.callback(ctx, **kwargs)
  File "main.py", line 39, in _slash
    await ctx.send('Message Sent ✅', ephemeral=True)
TypeError: send() got an unexpected keyword argument 'ephemeral'  

This code seems to work for other people, so I'm not sure what I'm doing wrong.

Python Version: 3.8
Pycord Version: Development (installed directly from dev branch this morning)


Solution

  • Discord uses 'respond' to respond to commands and 'send' to send a message to a specific channel. Only responses can be ephemeral so you should use

    await ctx.respond('Message Sent ✅', ephemeral=True)
    

    The important thing to understand is that you need an interaction to make a message ephemeral because without one, who would the message be ephemeral to? That‘s why it only works for responses to interactions.