【问题标题】:Discord Bot | Auto-Role不和谐机器人 |自动角色
【发布时间】:2020-11-08 15:14:07
【问题描述】:

我试图让我的机器人在用户加入服务器时赋予角色,但该事件不起作用。 它没有显示任何错误或任何东西,它只是不给角色。

我的代码:

@Client.event
async def on_member_join(member):
    intents = discord.Intents().all()
    client = commands.Bot(command_prefix = prefix, intents=intents)
    role = discord.utils.get(ctx.guild.roles, name='Unverified')
    await member.add_roles(role)

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    问题是ctx 没有定义。我还修复了你的结构。

    import discord 
    from discord.ext import commands
    
    intents = discord.Intents().all()
    Client= commands.Bot(command_prefix="$", intents=intents)
    
    @Client.event
    async def on_member_join(member):
        role = discord.utils.get(member.guild.roles, name='Unverified')
        await member.add_roles(role)
    
    client.run('TOKEN')
    

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 2019-02-02
      • 2020-12-15
      • 1970-01-01
      • 2021-01-06
      • 2021-01-22
      • 2021-05-22
      • 1970-01-01
      • 2021-04-23
      相关资源
      最近更新 更多