我又是第七次了. 我在做一个建议命令.当有人发送他们的建议时,它应该转到另一个渠道.我有一个日志(log)通道ID设置(log_channel_id),建议应该转到该通道.

代码:

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)

有没有人有办法得到用户设置为日志(log)ID的建议?谢谢:)

推荐答案

如果您的log_Channel_id是正确的,那么这将完成以下工作:

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)

Python相关问答推荐

是什么导致对Python脚本的jQuery Ajax调用引发500错误?

pyautogui.locateOnScreen在Linux上的工作方式有所不同

如何修复使用turtle和tkinter制作的绘画应用程序的撤销功能

DuckDB将蜂巢分区插入拼花文件

Python -根据另一个数据框中的列编辑和替换数据框中的列值

Django mysql图标不适用于小 case

删除所有列值,但判断是否存在任何二元组

将图像拖到另一个图像

在Python中管理打开对话框

SQLAlchemy Like ALL ORM analog

在极性中创建条件累积和

递归访问嵌套字典中的元素值

在Python中计算连续天数

手动设置seborn/matplotlib散点图连续变量图例中显示的值

python—telegraph—bot send_voice发送空文件

基于Scipy插值法的三次样条系数

pysnmp—lextudio使用next()和getCmd()生成器导致TypeError:tuple对象不是迭代器''

Python将一个列值分割成多个列,并保持其余列相同

在我融化极点数据帧之后,我如何在不添加索引的情况下将其旋转回其原始形式?

PySpark:如何最有效地读取不同列位置的多个CSV文件