首页 > 解决方案 > 在成员加入事件消息不起作用 - discord.py

问题描述

我对 discord.py 很陌生,我想学习 python 并为我的服务器制作一个简单的机器人。我想制作一个机器人,当有人加入服务器时发送消息。但机器人不会发送任何消息。我尝试了很多解决方案,但都没有奏效。

控制台没有错误。只是“on_member_join”不起作用;ping 和控制台消息方法有效。

这是我的代码:

    import discord
    from discord.ext import commands
    
    client = commands.Bot(command_prefix='*')
    TOKEN = '----my token here----'
    
    @client.event
    async def on_ready():
        print('Bot is ready')
    
    @client.event
    async def on_member_join(member):
        channel = client.get_channel(764960656553934879)
        await channel.send('Hello')
    
    @client.command()
    async def ping(ctx):
        await ctx.send('Pong!')
    
    client.run(TOKEN)

标签: pythondiscord

解决方案


discord.py 1.5.0,参考intents的介绍

您的机器人将需要该members意图 - 这恰好是一个特权意图- 以便on_member_join正确触发事件。


推荐阅读