問題描述
我正在嘗試使用 Discord.py 庫制作一個不和諧機器人.帶有 @client.command() 裝飾器的命令對我來說工作正常,但我嘗試過的事件都沒有工作.
I am trying to make a discord bot with the Discord.py library. The commands with the @client.command() decorator work fine for me, but none of the event ones that I tried work.
@client.event
async def on_member_join(member):
channel = client.get_channel(ChannelId) #I did define channel Id in my code
await channel.send("someone has joined")
@client.event
async def on_member_remove(member):
print("Someone has left")
我希望這會輸出到終端或我輸入的頻道 ID,但什么也沒有出現,甚至沒有錯誤消息.
I would expect this to output to the terminal or in the channel id I put in, but nothing appears, not even an error message.
*我用過客戶端.對于所有功能.*我在 mac 上做這個.
*I used client. for all functions. *I am doing this on mac.
我不太確定它為什么起作用,我沒有收到任何錯誤消息,而且我似乎找不到其他人遇到這個問題.
Im not quite sure why its working, I do not get any error messages, and I cant seem to find anyone else with this problem.
提前致謝
推薦答案
使用版本 >1.5.0 你可以這樣做:
With version >1.5.0 you can do something like this:
import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
@client.event
async def on_member_join(member):
await member.send("Welcome!")
這篇關于Discord.py on_member_join 不起作用,沒有錯誤消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!