【发布时间】:2021-08-13 03:14:12
【问题描述】:
@commands.command()
async def emojify(self, ctx, *, text):
emojis = []
for s in text.lower():
if s.isdecimal():
num2emo = {'0':'zero', '1':'one', '2':'two',
'3':'three', '4':'four', '5':'five',
'6':'six', '7':'seven', '8':'eight',
'9':'nine'}
emojis.append(f':{num2emo.get(s)}:')
elif s.isalpha():
emojis.append(f':regional_indicator_{s}:')
else:
emojis.append(s)
await ctx.send(''.join(emojis))
此命令将单词变成不和谐的表情符号(如 dank memer emojify)
如何让它在发送前检查消息字符长度的长度,以便它可以打印错误或继续?
【问题讨论】:
-
存储
''.join返回值并检查它的长度
标签: python python-3.x discord discord.py bots