python - 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")
解决方案
使用 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)
推荐阅读
- android - Android NFC如何实现一次贴卡多读卡?
- unit-testing - ES 模块的 Jest-Vue-Quasar 单元测试问题
- javascript - 从链接单击显示和隐藏表格
- c - 当使用 open 命令和 O_CREAT 时,它会附加一个“?” 到文件名的末尾,如何删除它?
- azure-logic-apps - 为当前比特币市场数据的 JSON 转换属性名称
- go - 为什么在Golang定义之前要使用引号
- function - Haskell - 使用相同的输入连接两个函数
- c++ - ${CMAKE_CURRENT_LIST_DIR} 和 . (相对目录)?
- python - 如何以 dd/mm/yyyy 格式验证用户输入的日期
- excel - 将每个数据集转换为 1 行