【问题标题】:on_member_join(member) is never called in discord.py在 discord.py 中永远不会调用 on_member_join(member)
【发布时间】:2022-04-26 15:06:56
【问题描述】:

我正在 python 3.8.6 上使用 discord.py 制作一个不和谐机器人。

我的其他功能,例如on_ready 和其他命令,可以正常工作。然而,on_member_join 在成员加入时不会被调用。

from discord.ext import commands
bot = commands.Bot(command_prefix =".")

@bot.event
async def on_ready():
    print('logged on salaud')

@bot.event
async def on_member_join(member):
    print("test")

bot.run("TOKEN")

为什么没有调用on_member_join,我该如何解决这个问题?

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    discord.py v1.5 介绍intents

    意图基本上允许机器人订阅特定的事件桶。

    为了能够获取服务器数据,您需要:

    • 在您的 application 中启用服务器成员意图

    • 并在代码开头实现discord.Intents

    import discord
    
    intents = discord.Intents.all()
    
    
    bot = discord.Client(intents=intents)
    
    # or 
    
    from discord.ext import commands
    bot = commands.Bot(command_prefix = ".", intents=intents)
    
    
    

    更多信息,请阅读Intents | documentation

    【讨论】:

    • 感谢您的回答,我完全放弃了这个选项(我为我的其他机器人做了)。多么棘手的问题^^
    猜你喜欢
    • 2021-02-08
    • 2020-10-14
    • 2021-02-25
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多