好的,所以我想制作它,它会问你想给它命名什么角色,然后你输入它,它说Type"?验证以获得对服务器的访问权限"我目前得到了这个,但它不起作用:/需要帮助
@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!**")
您的命令的逻辑不正确:
- 它接受您在args(
?verification test string
(中传递的内容→(test, string)
( - 检查author、channel和从args构建的字符串是否等于您等待的消息
- 您不会将收到的消息分配到任何位置
我建议用下面的方法之一:
-
使用命令参数(
?verification Role Name
→角色Role Name
创建(@bot.command() async def verification(ctx, *, rolename: str): """Create verification role""" # first kwarg is "consume-rest" argument for commands: https://discordpy.readthedocs.io/en/v1.3.4/ext/commands/commands.html#keyword-only-arguments await ctx.guild.create_role(name=rolename, hoist=True, reason="Verification Role Creation", colour=discord.Colour(0x979c9f)) await ctx.send("**Type ?verify to gain Access to the Server!**")
-
使用实际消息响应(
?verification
→Bot询问:What do you want to Name the Role?
→用户使用(示例中(Role Name
进行响应→角色Role Name
创建`@bot.command() async def verification(ctx): """Create verification role""" def check(message): return message.author == ctx.author and message.channel == ctx.channel await ctx.send("What do you want to Name the Role?") rolename = await bot.wait_for('message', check=check, timeout=60) await guild.create_role(name=rolename, hoist=True, reason="Verification Role Creation", colour=discord.Colour(0x979c9f)) await ctx.send("**Type ?verify to gain Access to the Server!**")