Discord.py on_member_join wont print

半腔热情 提交于 2021-02-10 15:45:46

问题


@client.event
async def on_member_join(member):
    print(member)

    role = discord.utils.get(member.guild.roles, name="☾│Unregister Of Hyperion")
    await member.add_roles(role)

This is my code, it should print the users nick when it joins, but it doesn't. The bot gives the role but it doesnt print. The same code works on my other bot. I have no idea why it doesnt work in this.


回答1:


In the new version of discord.py(1.5.x), there're some updates about Intents. Intents are similar to permissions, you have to define Intents to get channels, members and some events etc. You have to define it before defining the client = discord.Bot(prefix='').

import discord

intents = discord.Intent().all()
client = discord.Bot(prefix='', intents=intents)

@client.event
async def on_member_join(member):
    print(member)
    role = discord.utils.get(member.guild.roles, name="☾│Unregister Of Hyperion")
    await member.add_roles(role)

If you want to get more information about Intents, you can look at the API References.



来源:https://stackoverflow.com/questions/64536565/discord-py-on-member-join-wont-print

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!