gpt4 book ai didi

python - Discord py bot 未触发 on_member_join 函数

转载 作者:太空宇宙 更新时间:2023-11-03 20:01:07 26 4
gpt4 key购买 nike

我的不和谐 py 机器人不会触发“on_member_join”事件。其他一切都很好。我还有其他正常触发的事件方法。我在这里做错了什么?当人们加入时,它甚至不打印控制台语句。

# Libs
import discord # Version 1.2.5
from discord.ext import commands

# set discord API token
token = "MASKED"


# Initiate used objects
bot = commands.Bot(command_prefix="!")

@bot.event
async def on_member_join(member):
print(f"{member} has joined the server.")
for channel in member.server.channels:
if str(channel) == "general":
await bot.send_message(f"""Welcome to the server
{member.mention}""")

bot.run(token)

最佳答案

如果我是对的,问题是用户你的机器人启动之前加入。假设您使用备用帐户加入服务器进行测试,您应该尝试在机器人启动后打印一条消息,然后加入服务器。您可以通过以下代码来做到这一点。 https://discordpy.readthedocs.io/en/latest/api.html#discord.on_ready

#prints 'logged on' when bot is ready
@bot.event
async def on_ready():
print('logged on')

因此,在打印出“logined on”之后,您就可以加入服务器并查看它是否有效。

希望这能解决您的问题!

关于python - Discord py bot 未触发 on_member_join 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59229432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com