Python - 在用户加入时发送消息

Python - Send Messages Upon User Joining(Python - 在用户加入时发送消息)
本文介绍了Python - 在用户加入时发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

所以,我正在尝试使用最新版本的 Discord.Py 和 Python 3.6.4 来检测用户何时加入,它会向他们发送一条欢迎他们的消息.我的代码如下:

So, I am trying in the latest version of Discord.Py and Python 3.6.4 to detect when a user joins, it will send a message to them welcoming them. My code is as follows:

@client.event
async def on_member_join(member):
    await client.send_message(member,"Welcome!")

这段代码似乎不起作用,我已经查看了其他人是如何做到的,但是代码已经过时了,在 API 上也找不到关于我将如何做到这一点的任何内容.任何帮助表示赞赏!

This code doesn't seem to work, I have looked up already on how others did it but the code is outdated, couldn't find anything on the API either on how I would do this. Any help is appreciated!

主要好的,所以代码工作正常,但我收到 403 权限错误.Bot 以 FULL PERMISSIONS 重新邀请,并且在服务器中具有 FULL PERMISSIONS.所以我不知道为什么会这样.机器人可以随时随地发送消息,但不是专门在 on_memer_join(member) 下发送消息...为什么?

MAJOR Okay, so the code works fine but I'm getting a 403 Permissions Error. The Bot was re-invited with FULL PERMISSIONS and in server has FULL PERMISSIONS. So I have no idea why this is happening. The bot can send messages anytime anywhere but not specifically under the on_memer_join(member) ... why?

推荐答案

Discord.py的重写版本,需要开启Intents

For the Rewritten version of Discord.py, You need to enable Intents


intents = discord.Intents.all()
client = Bot.commands(command_prefix = '', intents = intents)

async def on_member_join(member):
    await member.send('Welcome!')

您还必须在机器人应用程序中启用意图.抱歉,这是一个迟到的评论.

You must enable intents in your bot application as well. Sorry this is a late comment.

这篇关于Python - 在用户加入时发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)