繁体   English   中英

如何使不和谐的机器人根据人员在命令中输入的内容来创建角色

[英]How can I make a discord bot create a role based on what the person types in the command

我是编码和制作不一致机器人的新手,我已经知道它是使用命令来扮演角色的,但是我无法根据人在命令中的输入来弄清楚如何使其扮演角色。 例如,!rolecreate test,如果我键入它,我希望它扮演一个称为test的角色并将其交给我。 如果有帮助,那么这里是我仅担任蓝色角色的代码,称为test。

https://pastebin.com/HMkLTkSe

@client.command(pass_context=True)
async def rolecreate(ctx):
    author = ctx.message.author
    await client.create_role(author.server, name='TEST', colour=discord.Colour(0x0000FF))

这未经测试,但是类似这样的方法应该起作用:

from discord.utils import get

@client.command(pass_context=True)
async def rolecreate(ctx):
    author = ctx.message.author
    # split the string to get the rolename to create
    role_name = ctx.message.content.lower().split("!rolecreate ", maxsplit=1)[1]
    # check if that role already exists
    check_for_duplicate = get(ctx.message.server.roles, name=role_name)
    if check_for_duplicate is not None: # if the role doesn't exist
        # create the role
        role = await client.create_role(author.server, name=role_name, colour=discord.Colour(0x0000FF))
        await client.add_roles(author, role)
    else:
        client.send_message(ctx.message.channel, "That role already exists")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM