谁能帮助我!怎么了谢谢!
@client.command()
@commands.has_permissions( manage_roles = True )
async def addrole( ctx, member: discord.Member = None, role: discord.Role = None, guild: discord.Guild = None ):
guild = ctx.guild if not guild else guild
emb = discord.Embed( title = 'Add role', colour = discord.Color.green())
await ctx.channel.purge( limit = 1 )
await client.add_roles( member, role )
emb.set_author( name = guild, icon_url = guild.icon_url )
emb.set_footer( text = 'Was added by {}'.format( ctx.author.name ), icon_url = ctx.author.avatar_url )
emb.set_thumbnail( url = member.avatar_url )
emb.add_field( name = 'Role added to user', value = '{}'.format( member.mention ) )
emb.add_field( name = 'Added role is', value = '{}'.format( role ) )
await ctx.send( embed = emb )
我试图自己编写代码并尝试观看教程,但是这些代码都不起作用。
答案 0 :(得分:0)
似乎您可能正在使用一些旧文档(v0.16.x)来添加角色。我建议您浏览更多最新的教程。
在重写(v1.x)中,add_roles()
的语法已更改,现在是discord.Member
对象中的方法:
@client.command()
async def addrole(ctx, member: discord.Member, role: discord.Role):
await member.add_roles(role)
await ctx.send(f"Successfully gave {role.name} to {member}!")
参考:
Member.add_roles()
答案 1 :(得分:0)
我编辑并得到了!
@client.command()
@commands.has_permissions( manage_roles = True )
async def addrole( ctx, member: discord.Member = None, role: discord.Role = None,
guild: discord.Guild = None ):
guild = ctx.guild if not guild else guild
emb = discord.Embed( title = 'Add role', colour = discord.Color.green())
await ctx.channel.purge( limit = 1 )
await member.add_roles( role )
emb.set_author( name = guild, icon_url = guild.icon_url )
emb.set_footer( text = 'Was added by {}'.format( ctx.author.name ), icon_url = ctx.author.avatar_url )
emb.set_thumbnail( url = member.avatar_url )
emb.add_field( name = 'Role added to user', value = '{}'.format( member.mention ) )
emb.add_field( name = 'Added role is', value = '{}'.format( role ) )
await ctx.send( embed = emb )