【发布时间】:2019-01-13 09:19:54
【问题描述】:
我怎样才能使这段代码具有caseSensitive?我试过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)
【问题讨论】:
标签: python bots discord discord.py