【问题标题】:How to send message in code format?如何以代码格式发送消息?
【发布时间】:2018-05-14 16:04:13
【问题描述】:

我尝试了类似的方法,但它不起作用。

async def example(ctx):
     await client.say("```python\n")
     await client.say("print('Hello world!')\n")
     await client.say("```")

您可以使用代码格式发送 Discord 消息。

但是如何在 python 中使用 discord API 做到这一点?

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    您需要发送一个连续消息。就像在不和谐中一样,如果您将代码格式的消息拆分为三个单独的消息,它不会呈现为代码:

    async def example(ctx):
         await client.say("```python\nprint('Hello world!')\n```")
    

    你也可以使用多行字符串:

    async def example(ctx):
         await client.say("""```python
    print('Hello world!')
    ```""")
    

    【讨论】:

    • 旁白:为了约定,我们通常将命令扩展客户端命名为bot
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多