带空格的不和谐命令?

时间:2020-10-20 17:35:54

标签: python command discord bots discord.py

我想创建一个不带空格的命令,但是它不起作用,我该如何解决?我希望该命令成为?help主持人,但由于某些原因我在两个单词之间不能有空格。

@commands.has_role('Staff')
@client.command(name='help moderator')

async def help_moderator(context):
    my_embed = discord.Embed(title="Moderator Plugin", color=0xFFC71C)
    my_embed.add_field(name="``?ban [member] (optional reason)``", value="Bans a member from the server",
                       inline=False)
    my_embed.add_field(name="``?tempban [member] [duration] (optional reason)``",
                       value="Temporarily bans a member from the server", inline=False)
    my_embed.add_field(name="``?mute [member] (optional reason)``", value="Mutes a member in the whole server",
                       inline=True)
    my_embed.add_field(name="``?tempmute [member] [duration] (optional reason)``",
                       value="Temporarily mutes a member in the server", inline=False)
    my_embed.add_field(name="``?kick [member] (optional reason)``", value="Kicks a member from the server",
                       inline=False)
    my_embed.add_field(name="``?unban [member]``", value="Unbans a member", inline=False)
    my_embed.add_field(name="``?unmute [member]``", value="Unmutes a member", inline=False)
    my_embed.set_thumbnail(
        url='https://cdn.discordapp.com/attachments/765665083082407976/767502481922981928/ModHammer.png')

    my_embed.set_footer(text="Work in progress, these commands are not in function yet.")

    await context.message.channel.send(embed=my_embed)

1 个答案:

答案 0 :(得分:0)

使用Commands扩展名时,命令名称或别名不能带有空格(这会导致某些消息解析问题)。

您必须使用on_message事件才能做到这一点:

from discord.utils import get

@bot.event
async def on_message(message):
    admin = get(message.guild.roles, name='Staff')
    if message.content.startswith('!help moderator') and admin in message.author.roles:
        #Your code here