【问题标题】:EMBED SYSTEM [IDLE PYTHON]嵌入系统 [空闲 Python]
【发布时间】:2021-11-18 02:35:26
【问题描述】:

所以我有一个嵌入系统在下面的代码中工作:

@client.event
async def on_message(message):
  if message.content.startswith('!emsay'):
    embedVar = discord.Embed(title="Title", description="desc", color=0x00ff00)
    await message.channel.send(embed=embedVar)

我的问题是,当我执行 !emsay 时,它会嵌入嵌入,但有没有办法在我放入 !emsay 后更改标题和描述,而无需进入 python 输入全新的嵌入? 这就是我目前拥有的:(我很好)Discord screenshot of embed 我想这样做,所以在我使用命令后!emsay 我可以通过不和谐输入标题和描述。 谢谢 : ) 对不起,如果 iv 过于复杂了

【问题讨论】:

    标签: discord discord.py bots embed


    【解决方案1】:

    试试这个:

    @client.event
    async def on_message(message):
        if message.content.startswith('!emsay'):
            count = 0
            def check(author):
                def inner_check(message):
                    if message.author != author:
                        return False
                return inner_check
    
            while count < 2:
                if (count == 0):
                    await message.channel.send("Write a title for embed")
                    title = await client.wait_for("message", check=check, timeout=30)
                elif (count == 1):
                    await message.channel.send("Write a desc for embed")
                    desc = await client.wait_for("message", check=check, timeout=30)
                count += 1
            
            embedVar = discord.Embed(title = title.content, description = desc.content, color = 0x00ff00)
            await message.channel.send(embed=embedVar)
    

    如果你不写title和desc,你会得到一个TimeoutError,你可以根据需要更改超时。

    How to use?

    【讨论】:

    • 谢谢 尝试过,但在尝试输入标题时出现此错误我该怎么办?忽略 on_message Traceback 中的异常(最后一次调用):文件“C:\Users\Kaii Hannam\AppData\Roaming\Python\Python39\site-packages\discord\client.py”,第 343 行,在 _run_event await coro(* args, **kwargs) 文件“D:\bots\test bot.py”,第 26 行,on_message 标题 = await self.bot.wait_for("message", check=check, ti​​meout=30) NameError: name 'self ' 未定义
    • 抱歉,我忘记将 self.bot 更改为客户端。我现在编辑它。你能再试一次吗?
    猜你喜欢
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2014-07-05
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多