【问题标题】:On member join event message doesn't work - discord.py在成员加入事件消息不起作用 - discord.py
【发布时间】:2020-10-13 09:07:55
【问题描述】:

我是 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)

【问题讨论】:

  • 发现会员加入时on_member_join事件根本没有运行

标签: python discord


【解决方案1】:

对于 discord.py 1.5.0,请参考 introduction of intents。

您的机器人将需要 members 意图 - 恰好是 priveleged intent - 以便正确触发 on_member_join 事件。

【讨论】:

    猜你喜欢
    • 2020-09-29
    • 2021-05-16
    • 1970-01-01
    • 2020-09-16
    • 2021-08-23
    • 2021-04-17
    • 2022-07-23
    • 2021-06-30
    • 2021-03-26
    相关资源
    最近更新 更多