Search code examples
discord.pynextcord

Is there any way to send a DM to Slash Command author in nextcord/discord.py?


Ive tried the following code:

@bot.slash_command()
async def test(interaction: nextcord.Interaction):
    await interaction.response.author.send_message(f"Test DM")

But it gives me the following error: nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'InteractionResponse' object has no attribute 'author'

I have no idea on how to fix this, ive tried searching and I can't find anything, can anyone help me?


Solution

  • A quick look at the docs would tell you that InteractionResponse.author indeed doesn't exist. Using random attributes/methods and hoping it leads somewhere rarely does anything useful.

    Similarly, another quick look at the docs will tell you that Interaction has a user attribute of which the description is

    The user or member that sent the interaction.