skip to Main Content

I’m making a Discord bot with Python, the code is the following:

embed = discord.Embed(title=f'Topic: {tema.capitalize()}',
                      description='The word has ' + str(len(secretWord)) + ' letters',
                      color=discord.Color.yellow())
msg = await interaction.response.send_message(embed=embed)
await msg.add_reaction('regional_indicator_1:')

It gives me the following error that I can’t understand:

discord.app_commands.errors.CommandInvokeError: Command ‘hm’ raised an exception: AttributeError: ‘NoneType’ object has no attribute ‘add_reaction’

2

Answers


  1. The response cannot be saved as a message that can be reacted to.
    Instead you should use msg = await interaction.channel.send(embed=embed) this will create a message variable for msg instead of a response.

    Login or Signup to reply.
  2. As Rexy had mentioned, InteractionResponse.send_message does not return any value, unlike Channel.send which returns the Message object of the message that was sent.

    You can get the original_response (response sent with InteractionResponse) with the Interaction.original_response method.

    await interaction.response.send_message(content="...")
    message = await interaction.original_response() #  Asynchronous method
    await message.add_reaction("✅")
    

    For more information: InteractionResponse, InteractionResponse.send_message, Interaction.original_response

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search