discord.py – How do i move a users suggestion to another channel?

me once again for the 7th time.
I’m making a suggestion command. When someone sends their suggestion, it should go to another channel. I have a log channel ID set ( log_channel_id ), the suggestion should go to that channel.

Code:

class View(discord.ui.View):
    def __init__(self):
        super().__init__()

    @discord.ui.button(label='Confirm', style=discord.ButtonStyle.green)
    async def asdf(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.edit_message(content="Your suggestion has been sent successfully.",embed=None,view=None)
        # the suggestion should be sent to another channel, i already have a channel ID set for it (log_channel_id)


@bot.tree.command(name="suggest", description="Make a suggestion with this command.")
async def hello(interaction: discord.Interaction, title: str, description: str):
    if interaction.user.id in blacklist:
        embed = discord.Embed(title=f"Unable to execute command.\nReason: blacklisted", color=discord.Color.red())
        await interaction.response.send_message(embed=embed, ephemeral=True)
    else:
        embed = discord.Embed(title=f"Is this information correct?", description=f"sdfsdfsdfsd", color=discord.Colour.random())
        embed.set_thumbnail(url=f"{interaction.user.avatar.url}")
        embed.add_field(name=f"Title", value=f"{title}", inline=False)
        embed.add_field(name="Description", value=f"{description}")
        embed.set_footer(text=f"USER ID: {interaction.user.id}")
        await interaction.response.send_message(embed=embed, view=View(), ephemeral=True)

Anyone have a idea to get the suggestion the user set to the log ID? thanks 🙂

>Solution :

If you got the log_channel_id correct then this will do the work:

class View(discord.ui.View):
    def __init__(self, embed):
        super().__init__()
        self.embed = embed

    @discord.ui.button(label='Confirm', style=discord.ButtonStyle.green)
    async def asdf(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.edit_message(content="Your suggestion has been sent successfully.", embed=None, view=None)
        channel = interaction.guild.get_channel(log_channel_id)
        await channel.send(embed=self.embed)

@bot.tree.command(name="suggest", description="Make a suggestion with this command.")
async def hello(interaction: discord.Interaction, title: str, description: str):
    embed = discord.Embed(title=f"Is this information correct?", description=f"sdfsdfsdfsd", color=discord.Colour.random())
    embed.set_thumbnail(url=f"{interaction.user.avatar.url}")
    embed.add_field(name=f"Title", value=f"{title}", inline=False)
    embed.add_field(name="Description", value=f"{description}")
    embed.set_footer(text=f"USER ID: {interaction.user.id}")

    view = View(embed)
    await interaction.response.send_message(embed=embed, view=view, ephemeral=True)

Leave a Reply