問題描述
所以,我正在嘗試使用最新版本的 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 - 在用戶加入時發送消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!