Python - Send Messages Upon User Joining(Python - 在用户加入时发送消息)
问题描述
所以,我正在尝试使用最新版本的 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 - 在用户加入时发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python - 在用户加入时发送消息
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01