简体   繁体   English

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

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

I am new to coding and making discord bots, I have gotten it to make a role using a command but I can't figure out how to make it make a role based on what the person puts in the command. 我是编码和制作不一致机器人的新手,我已经知道它是使用命令来扮演角色的,但是我无法根据人在命令中的输入来弄清楚如何使其扮演角色。 For example, !rolecreate test, if I typed that I want it to make a role called test and give it to me. 例如,!rolecreate test,如果我键入它,我希望它扮演一个称为test的角色并将其交给我。 If it helps here is the code I have for just making a blue role called test. 如果有帮助,那么这里是我仅担任蓝色角色的代码,称为test。

https://pastebin.com/HMkLTkSe 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))

This is untested, but something like this should work: 这未经测试,但是类似这样的方法应该起作用:

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.

相关问题 我将如何做到这一点,以便个人是唯一可以使用 discord 机器人运行命令的人? - How would I make it so that an individual person is the only one who can run a command with a discord bot? 如何制作自定义不和谐机器人@某人,某人在命令中@ed? - How do I make a custom discord bot @ someone that a person @ed in the command? 如何做到这一点,以便我的 discord 机器人只接受启动命令的人的输入 - How do I make it so my discord bot only take inputs from the person that started the command 如何让不和谐的机器人在命令中提及我和我提及的人 - How to get discord bot to mention me and the person i mention in the command 如何让我的 Discord 机器人提及频道中的特定人员? - How can i make my Discord bot mention a specific person in the channel? 我怎样才能让我的 discord 机器人在键入时提到特定的人? - How can I make it so my discord bot mentions a specific person when they type? 如何为 Discord Bot 创建角色 - How to create a role for a Discord Bot 如何让discord bot在discord.py中的命令后接受输入? - How can I make a discord bot take input after a command in discord.py? 当我的机器人或其他机器人在命令中使用时,如何让我的机器人说些什么? (不和谐.py) - How can I make my bot say something when it or another bot is used in the command? (discord.py) discord.py中的bot命令重新写入,如何基于角色包含AND角色不包含的条件分支? - bot command in discord.py REWRITE, how to conditional branch based on role contains AND role doesnt contain?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM