【问题标题】:on_member_join event discord.pyon_member_join 事件 discord.py
【发布时间】:2021-01-08 06:01:49
【问题描述】:

我用on_member_join事件制作了一个自动角色分配系统,它一直工作到现在,现在它没有向成员发送消息,也没有分配角色。请帮忙:

@bot.event
async def on_member_join(member):
    Role1 = discord.utils.get(member.guild.roles, id = 723244173779533925)
    await member.add_roles(Role1)
    Role2 = discord.utils.get(member.guild.roles, id = 723244271628582962)
    await member.add_roles(Role2)
    Role3 = discord.utils.get(member.guild.roles, id = 723563998393663499)
    await member.add_roles(Role3)
    await member.send('Hi, welcome to my server! In 30 seconds i will give you verified role, please **read rules** in that time.')
    await asyncio.sleep(30)
    verifiedRole = discord.utils.get(member.guild.roles, id = 788393533874765855)
    await member.add_roles(verifiedRole)
    await member.send('I given you the verified role, and you have access to the rest of the guild.')

【问题讨论】:

  • 嗨,它会抛出任何异常吗?
  • 不,不是。只是不工作

标签: python discord discord.py


【解决方案1】:

听起来你需要意图。

您需要在bot 的定义上方添加此代码:

intents = discord.Intents.default()
intents.members = True

现在,将 intents=intents 参数添加到意图位下方的机器人初始化中:

intents = discord.Intents.default()
intents.members = True
# If you have commands.Bot, add `intents = intents` in the parentheses:
bot = commands.Bot(your_options_here,intents = intents)
# If you have discord.Client(), add `intents = intents` into the parentheses:
bot = discord.Client(intents = intents)

确保在developer portal 中启用成员意图。 你可以阅读更多的意图here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 2021-01-16
    • 1970-01-01
    • 2021-05-08
    • 2021-02-25
    • 2021-02-08
    相关资源
    最近更新 更多