首页 > 解决方案 > 如何使用带有 python 的不和谐机器人发出欢迎消息?

问题描述

我是使用 python 制作不和谐机器人的新手,我想制作一个在有人加入服务器时显示欢迎消息的事件。

我试过这段代码

import discord
import random
from discord.ext import commands

alfred = commands.Bot(command_prefix = '!', description = "Hey!, I'm Alfred, How can I assist you?")

#EVENT

@alfred.event
async def on_ready():

    print("I'm Alfred and I'm Online!")

@alfred.event
async def on_member_join(member):
    embed=discord.Embed(title="Welcome!",description=f"{member.mention} Just Joined")
    await message.channel.send(embed=embed)

但它没有用,甚至不和谐的文档也说该事件是“on_member_join”。

我真的希望你能帮助我:)

标签: pythondiscordbotsdiscord.py

解决方案


试试这个,只需790274325533378682用您的频道 ID替换

@alfred.event
async def on_member_join(member):
    channel = alfred.get_channel(790274325533378682)
    embed=discord.Embed(title="Welcome!",description=f"{member.mention} Just Joined")
    await channel.send(embed=embed)

推荐阅读