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

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

上一篇:Discord.py 狙击命令 下一篇:在 Django 中运行 Discord 机器人

相关文章