我正在尝试使用 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 不起作用,没有错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!