我正在为discord编写一个bot,如果字符串不区分大小写,我希望这样做,但我不知道怎么做

8cdiaqws  于 2021-08-25  发布在  Java
关注(0)|答案(2)|浏览(348)

这是我不想区分大小写的一行:if message.content.startswith('.rich'):我想把它改成小写,但我还没有弄清楚如何在代码中实现它

import discord
from discord.ext import commands
import os
from keep_alive import keep_alive

client = discord.Client()

from discord.utils import find

@client.event
async def on_message(message):
  if message.content.startswith('.rich'):
    embed1 = discord.Embed(title='Richard I (Flag Defense)')
    embed1.set_image(url='https://cdn.rok.guide/wp-content/uploads/2019/09/richard-flag-defense-talent-build.jpg')
    embed1.set_author(name='Talent Builder', icon_url='https://cdn.discordapp.com/attachments/821829884967649291/860267265404305473/TB7.2t.png')

    embed2 = discord.Embed(title="Richard I (Garrison)")
    embed2.set_image(url='https://cdn.rok.guide/wp-content/uploads/2019/09/richard-i-garrison-talent.jpg')
    embed2.set_author(name='Talent Builder', icon_url='https://cdn.discordapp.com/attachments/821829884967649291/860267265404305473/TB7.2t.png')

    embed3 = discord.Embed(title="Richard I (Infantry)")
    embed3.set_image(url='https://cdn.rok.guide/wp-content/uploads/2019/09/richard-i-infantry-talent.jpg')
    embed3.set_author(name='Talent Builder', icon_url='https://cdn.discordapp.com/attachments/821829884967649291/860267265404305473/TB7.2t.png')

    await message.channel.send(embed=embed1)
    await message.channel.send(embed=embed2)
    await message.channel.send(embed=embed3)```
pbgvytdp

pbgvytdp1#

试着编辑这行

if message.content.startswith('.rich'):

为此:

if message.content.lower().startswith('.rich'):
cedebl8k

cedebl8k2#

使字符串区分大小写的一种简单方法是使用 .lower() 方法如下:

if message.content.lower().startswith('.rich'):

# '.rich' must be lowercase for anything to return true

这个 .lower() 将每个字符设置为其小写自身。这将允许任何大写或小写字母通过if语句,而不区分大小写。

相关问题