Python 我如何使它读取用户所说的内容并使用它来创建角色?不和谐
好的,我想这样做,它会问你想给它命名什么角色,然后你输入它,它会说键入“?验证以获得对服务器的访问权限!”我目前得到了这个,但它不起作用:/需要帮助吗Python 我如何使它读取用户所说的内容并使用它来创建角色?不和谐,python,discord,discord.py,Python,Discord,Discord.py,好的,我想这样做,它会问你想给它命名什么角色,然后你输入它,它会说键入“?验证以获得对服务器的访问权限!”我目前得到了这个,但它不起作用:/需要帮助吗 @bot.command() async def verification(ctx, *args): guild = ctx.guild msg = ' '.join(args) def check(message): return message.author == ctx.author and message.channe
@bot.command()
async def verification(ctx, *args):
guild = ctx.guild
msg = ' '.join(args)
def check(message):
return message.author == ctx.author and message.channel == ctx.channel and message.content.lower() == msg
await ctx.send("What do you want to Name the Role?")
await bot.wait_for('message', check=check, timeout=60)
await guild.create_role(name=msg, hoist=True, reason="Verification Role Creation", colour=discord.Colour(0x979c9f))
await ctx.send("**Type ?verify to gain Access to the Server!**")
您的命令逻辑不正确:
?验证测试字符串
→(测试,字符串)
)- 使用命令参数(
→ 角色?验证角色名称
已创建)角色名称
@bot.command() 异步def验证(ctx,*,角色名称:str): “”“创建验证角色”“” #第一个kwarg是命令的“使用rest”参数:https://discordpy.readthedocs.io/en/v1.3.4/ext/commands/commands.html#keyword-只有论点 等待ctx.guild.create_角色(name=rolename,chift=True,reason=“验证角色创建”,color=discord.color(0x979c9f)) 等待ctx.send(“**类型?验证以获得对服务器的访问权!**”)
- 使用实际消息响应(
→ Bot询问:?验证
→使用(示例中)您想给角色命名什么?
角色名称的用户响应→角色
已创建`角色名称
@bot.command() 异步def验证(ctx): “”“创建验证角色”“” def检查(消息): 返回message.author==ctx.author和message.channel==ctx.channel 等待ctx.send(“您想给角色命名什么?”) rolename=wait bot.wait_for('message',check=check,timeout=60) 等待公会。创建_角色(name=rolename,hugh=True,reason=“验证角色创建”,color=discord.color(0x979c9f)) 等待ctx.send(“**类型?验证以获得对服务器的访问权!**”)