我又是第七次了. 我在做一个建议命令.当有人发送他们的建议时,它应该转到另一个渠道.我有一个日志(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相关问答推荐

try 理解PyTorch运行错误:try 再次向后遍历图表

无法从文章复制Forking 图

如何在python中为列表中的每个项目分配来自另一个列表的相等数量的项目

在错误处理期间使用字典理解中的变量是否安全?

Tkinter和动画.FuncAnimation累积延迟和冻结GUI

在Pandas 数据帧中使用GROUPBY()应用FIND_PEAKS()函数

如何在Polars数据框中查找列表数据类型列中的最大值

导入错误:无法导入PerfetoLibrary

在LangChain和OpenAI嵌入中没有从链中获取源文档

在Turtle中单击某个形状时绑定事件

将日期列转换为从开始日期开始的天数

从源代码构建Python,已构建但未导入_sqlite3

如何在不引发异常的情况下将来自服务总线触发的Python Azure函数的消息添加回队列?

在Django中,当我比较两个HTML文本时,如何删除空行,以使比较成为积极的,尽管有空行?

Pandas Python-如何使用Pandas从包含分组/可折叠列文件的EXCEL中读取数据

在PIPE中使用时,PythoncsvWriter会导致";BrokenPipeError

将NaN替换为0,从每行第一个非NaN值之后开始

有没有办法只将两个NumPy数组的特定元素相加在一起?

Polars基于列的绝对值进行排序

光线跟踪中的高效渲染优化--避免全景渲染