Python 如何使机器人在discord.py中不区分大小写?
这包括前缀和命令,以及在Discord中键入的几乎所有内容。这是我的密码:Python 如何使机器人在discord.py中不区分大小写?,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,这包括前缀和命令,以及在Discord中键入的几乎所有内容。这是我的密码: from discord.ext import commands import discord.member from dotenv import load_dotenv import discord from discord.utils import get bot = commands.Bot(command_prefix="bot ") TOKEN = "48932859034578973498579382757
from discord.ext import commands
import discord.member
from dotenv import load_dotenv
import discord
from discord.utils import get
bot = commands.Bot(command_prefix="bot ")
TOKEN = "4893285903457897349857938275732985" #not a valid token by the way :)
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.command(name='image', help='Example command')
async def image(ctx):
#code for function goes here
pass
bot.run(TOKEN)
Bot命令可以不区分大小写,但是discord.py中没有使前缀不区分大小写的功能。然而,有一种方法可以解决这个问题
使bot命令不区分大小写
更改bot=commands.bot(command\u prefix=“prefix!”)
收件人:bot=commands.bot(不区分大小写=True,command\u prefix=“prefix!”)
使前缀不区分大小写
老实说,我并不推荐这样做,但是如果您真的需要不区分大小写的前缀,请遵循下面的代码
创建一个名为mixedCase()的函数
现在修改bot=commands.bot(command\u prefix=“prefix!”)
tobot=commands.bot(command\u prefix=mixedCase(“prefix!”)
最终代码
def mixedCase(*args):
"""
Gets all the mixed case combinations of a string
This function is for in-case sensitive prefixes
"""
total = []
import itertools
for string in args:
a = map(''.join, itertools.product(*((c.upper(), c.lower()) for c in string)))
for x in list(a): total.append(x)
return list(total)
from discord.ext import commands
import discord.member
from dotenv import load_dotenv
import discord
from discord.utils import get
def mixedCase(*args):
"""
Gets all the mixed case combinations of a string
This function is for in-case sensitive prefixes
"""
total = []
import itertools
for string in args:
a = map(''.join, itertools.product(*((c.upper(), c.lower()) for c in string)))
for x in list(a): total.append(x)
return list(total)
bot = commands.Bot(case_insensitive=True, command_prefix=mixedCase("prefix" ))
TOKEN = "4893285903457897349857938275732985" #not a valid token by the way :)
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.command(name='image', help='Example command')
async def image(ctx):
#code for function goes here
pass
bot.run(TOKEN)