discord.py 机器人可以不区分大小写吗? [英] Can a discord.py bot not be case sensitive?

本文介绍了discord.py 机器人可以不区分大小写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!



I'm making a discord bot right now, and it won't respond if I use capitals/don't use capitals. Is there a way for a bot to detect messages even if they're capital/lowercase? Is there also a way for a bot to be able to do the same with spaces (if I accidentally forget to put a space, or accidentally merge two words together...)?

还是我必须对 if 语句进行无穷无尽的跟踪?

Or do I have to make an endless trail of if statements?


假设你在 msg 变量中得到你的消息,那么如果你使用 msg.lower()您将获得小写版本的响应,您可以检查它以查看命令是什么.

assuming you get your message in the msg variable, then if you use msg.lower() you'll get the lowercase version of the response and you can check on that to see what the command was.

另外,运行 msg.replace(' ', '') 将创建一个删除所有空格的值,您可以检查此变量的相应值而不是原始值.

also, running msg.replace(' ', '') would create a value where all spaces are removed, and you can check the corresponding value of this variable instead of the original one.


msg = 'HeLlO wOrLd'
print(msg.lower().replace(' ', ''))
>> helloworld

假设这是一个命令行界面,我真的建议您遵循内置 argparse 库中的指南.

assuming this is a command line interface, I truly suggest you follow the guidelines in the builtin argparse library.


这篇关于discord.py 机器人可以不区分大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
发送“验证码”获取 | 15天全站免登陆