interaction.response.channel.send problem

34 Views Asked by At
async def callback(self, interaction: discord.Interaction):
    embed = discord.Embed(title="Modal Results")
    embed.add_field(name="test", value=self.children[0].value)
    embed.add_field(name="test", value=self.children[1].value)
    channel = client.get_channel(1201684034531368994)
    await interaction.response.channel.send(embed)

    await interaction.response.channel.send(embed)

i dont have any idea to fix this line can help me

2

There are 2 best solutions below

0
Some Things On

Here's a revised version of your code:

async def callback(self, interaction: discord.Interaction):
    embed = discord.Embed(title="Modal Results")
    embed.add_field(name="test", value=self.children[0].value)
    embed.add_field(name="test", value=self.children[1].value)
    channel = await client.fetch_channel(1201684034531368994) # Changed get_channel to fetch_channel and added 'await' (I personally prefer fetch)channel
    await channel.send(embed = embed) #channel already has attribute "send"

    await channel.send(embed = embed) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Explanation:

You already got the channel object, so now you can just send a message through the channel object.

1
Neko no akuma On

Here is the code that I edit, hope it can help you

async def callback(self, interaction: discord.Interaction):
    embed = discord.Embed(title="Modal Results")
    embed.add_field(name="test", value=self.children[0].value)
    embed.add_field(name="test", value=self.children[1].value)
    channel = client.get_channel(1201684034531368994)
    await channel.send(embed=embed)
    #You need to send at least a response for the interaction
    await interaction.response.send_message(embed=embed)

You may also need to read the doc of pycord, here is the link
https://docs.pycord.dev/