首页 > 解决方案 > Discord.py 模拟命令

问题描述

我正在尝试制作一个模拟命令。喜欢的用户可以输入“!mock hello you”。机器人应该输出“HeLlO yOu”。我没有计划如何做到这一点,也许你可以帮助我:D

    @bot.command()
    async def mock(ctx, *, message):
        await ctx.send("Here should the bot send the mocked message")

标签: pythondiscord.py-rewrite

解决方案


使用 random 模块并假设您以正确的方式传递整个消息:

@bot.command()
async def mock(ctx, *, message):
    out = ''.join(random.choice((str.upper, str.lower))(c) for c in message)
    await ctx.send(out)

推荐阅读