不在 Discord 中发送欢迎消息(使用 discord.py)

Not sending in Welcome Message in Discord (using discord.py)

我是 Python 和 StackOver 流程​​的新手。我正在为我的公会编写 Discord Bot。我要添加的第一个功能是在特定频道中发送欢迎消息。我对它进行了编码,当 运行 我没有收到任何错误...但是当有人加入我的服务器时,机器人没有发送任何消息。

这是我的代码:

from discord.ext import commands
import discord

bot = commands.Bot(command_prefix='-')
TOKEN = '<Bot Token>'

@bot.event
async def on_ready():
print("Succesfully logged in as {0.user}".format(bot))

@bot.event
async def on_memeber_join(member):
try:
    channel = bot.get_channel(<Channel ID>)
    await channel.message.send(
        'Welcome to PRIME CLUB {0.mention}'.format(member))
except Exception as e:
    print(e)


bot.run(TOKEN)

请帮我改正错误... 提前致谢

要使 on_member_join 正常工作,您需要在您的代码和机器人的仪表板上启用 Members Intent。有关如何执行此操作的信息在 API Docs.

此外,您拼写 member 错误(“memeber”)。您的缩进看起来也不对(进入函数内部时有 1 个制表符)。

# Enable intents
intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix='-', intents=intents)

@bot.event
async def on_ready():
    # Fix indentation
    print(...)

# Spell the name of the event correctly
@bot.event
async def on_member_join(member):
    # Fix indentation
    try:
        channel = ...

感谢@stijndcl 的帮助.... 目前这个脚本对我来说效果很好..

@bot.event
async def on_member_join(member):
    for channel in member.guild.channels:
        if str(channel.id) == '<CHANNEL ID>':
            await channel.send(f'Welcome!! {member.mention}')