简体   繁体   中英

How can I make a welcome message with a discord bot with python?

I'm new making a discord bot with python and I want o make a event that display a welcome message when someone joins the server.

I tried with this code

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)

But It didn't work, even the documentation of discord says the event is "on_member_join".

I really hope you can help me:)

Try this, just replace the 790274325533378682 with your channel 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM