不一致的py bot没有在成员连接函数上触发

2024-05-23 22:45:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我的不和谐py机器人不会触发“加入会员”事件。其他的都很好。我有其他正常触发的事件方法。我做错什么了?当人们加入时,它甚至不打印console语句。你知道吗

# 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)

Tags: the方法pyimporttokenserverbotchannel
2条回答
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game


Client=discord.client
client=commands.Bot(command_prefix='^')
Clientdiscord=discord.Client()
client.remove_command("help")

@client.event
async def on_member_join(member):
    print(f'Recognised that a member called {member} joined')
    await member.send(".")
    print('Sent message to ' + member.name)

这是我使用的脚本,我已经添加了我的机器人最上面的部分,以显示它去了哪里。你知道吗

如果我是对的,问题是用户在你的机器人启动之前加入了。 假设您使用备用帐户加入服务器进行测试, 您应该尝试在bot启动后打印消息,然后加入服务器。 您可以通过以下代码来实现这一点。 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')

因此,在打印登录后,您可以加入服务器并查看它是否工作。你知道吗

我希望这能解决你的问题!你知道吗

相关问题 更多 >