Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.73k stars 461 forks source link

Deferred message cannot return as ephemeral #2485

Closed zoomingspeed closed 4 months ago

zoomingspeed commented 4 months ago

Summary

When using ctx.defer(), it cannot return an ephemeral message, whether you use ctx.followup.send() or ctx.respond()

Reproduction Steps

  1. Call ctx.defer()
  2. Make a message send after it defers, include the ephemeral parameter too.

Minimal Reproducible Code

import discord
from discord.ext import commands

bot = discord.Bot(intents=discord.Intents.all())

@bot.slash_command(name="wtv", description="wtv")
async def hi(ctx):
    await ctx.defer()
    await asyncio.sleep(1)
    await ctx.followup.send("Hello!", ephemeral=True)

# Or if we wanna do the same thing but with ctx.respond:
@bot.slash_command(name="wtv", description="wtv")
async def hi(ctx):
    await ctx.defer()
    await asyncio.sleep(1)
    await ctx.respond("Hello!", ephemeral=True)

Expected Results

Return an ephemeral message as expected

Actual Results

Returns the message, but it is not ephemeral

Intents

discord.Intents.all()

System Information

import pkg_resources

(vscode.dev environment)

Checklist

Additional Context

Note, also using ctx.send() makes the program return a type error:

Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/commands/core.py", line 131, in wrapped
    ret = await coro(arg)
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/commands/core.py", line 1013, in _invoke
    await self.callback(ctx, **kwargs)
  File "/workspaces/sheikh-bot/sheikh-dev.py", line 837, in prayertimes
    await ctx.send(embed=embed, ephemeral=True)
TypeError: Messageable.send() got an unexpected keyword argument 'ephemeral'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/bot.py", line 1130, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/commands/core.py", line 376, in invoke
    await injected(ctx)
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/commands/core.py", line 139, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: Messageable.send() got an unexpected keyword argument 'ephemeral'
Blue-Robin-Taken commented 4 months ago

Do we know if this is a discord limitation or just the library

Vondyy commented 4 months ago

pass this ephemeral=True in your defer.

Blue-Robin-Taken commented 4 months ago

@Vondyy This is supported by the docs https://docs.pycord.dev/en/stable/api/application_commands.html#discord.ApplicationContext.defer

Dorukyum commented 4 months ago

await ctx.defer(ephemeral=True) if you're eventually going to send an ephemeral response.