使代码不区分大小写敏感,Python,Discord Bot

时间:2018-08-06 12:03:24

标签: python bots discord discord.py

如何使此代码成为icaseSensitive?我已经尝试过bot = commands.Bot(command_prefix=';', case_insensitive=True 我在重写分支上的代码在这里吗?我知道如何使用async def on_message,但听说使用async def on_message

并不聪明

代码:

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio


bot = commands.Bot(command_prefix=';', case_insensitive=True)

@bot.command(pass_context=True)
@commands.has_role("Admin")
async def info(ctx, user: discord.Member):
    embed = discord.Embed(title="{}'s info:".format(user.name), description="Here is his description. Bounty is around 1000 Dubloons", color=0x00ff00)
    embed.add_field(name="Navn", value=user.name, inline=True)
    embed.add_field(name="ID", value=user.id, inline=True)
    embed.add_field(name="Status", value=user.status, inline=True)
    embed.add_field(name="Høyeste rolle", value=user.top_role)
    embed.add_field(name="Ble med", value=user.joined_at)
    embed.set_thumbnail(url=user.avatar_url)
    await bot.say(embed=embed)

编辑:

    from itertools import product

def aliases(info):
    return [''.join(item) for item in product(*((c.lower(), c.upper()) for c in info))]

@bot.command(pass_context=True, aliases=aliases('info'))
@commands.has_role("Admin")
async def info(ctx, user: discord.Member):
    embed = discord.Embed(title="{}'s info:".format(user.name), description="Here is his description. Bounty is around 1000 Dubloons", color=0x00ff00)
    embed.add_field(name="Navn", value=user.name, inline=True)
    embed.add_field(name="ID", value=user.id, inline=True)
    embed.add_field(name="Status", value=user.status, inline=True)
    embed.add_field(name="Høyeste rolle", value=user.top_role)
    embed.add_field(name="Ble med", value=user.joined_at)
    embed.set_footer(text="© Solmester123456 // Thomas")
    embed.set_thumbnail(url=user.avatar_url)
    await bot.say(embed=embed)

1 个答案:

答案 0 :(得分:0)

尝试运行import discord; print(discord.__version__)。重写分支为1.0,异步分支为0.16。我怀疑您在异步分支上。

权宜之计是将每个混合首字母缩写注册为别名,例如

from itertools import product

def aliases(word):
    variations = (''.join(item) for item in product(*((c.lower(), c.upper()) for c in word)))
    return [item for item in variations if item != word]
    # registering the name of the coroutine as an alias causes it to fail

@bot.command(pass_context=True, aliases=aliases('info'))
@commands.has_role("Admin")
async def info(ctx, user: discord.Member):
    ...

编辑:以前这是行不通的,因为product返回的是元组而不是字符串,因此我们需要将它们连接成单词。