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

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

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)