Recents in Beach

How to send embedded welcome message with discord.py - pygodz


How to send welcome message with discord.py

We all want to welcome are newly joined members with charming welcome message. In this article you will learn to make the discord.py bot send customs embedded welcome messages when someone joins your server.

Note: This tutorial is going to be a bit of advanced , I will try my best to make things clear and easier as much as possible but you need atleast basic knowledge of python to understand what's going on here.
If you don't know how to make a discord bot with python , I suggest you should go and read my this article first, (click here) I have taught here the easiest way to do so , you can also watch my hindi tutorial video on youtube which also explains the same thing How to make a discord bot in python?



So, from now I will expect that you have atleast basic knowledge of
python and you know how things work.

Now you can head towards the real tutorial on how to make the discord.py bot send embedded welcome messages when someone joins.

You can watch my hindi tutorial video here,

First of all choose a welcome channel and copy its id . If you don't know how to get id of any channel , Follow these simple steps:
  • Go to user settings from discord app or website.
  • Click the appearance tab, you will find developer options there.
  • Enable developer options.
  • Discord: How to get id of any channel

    Discord: How to get id of any channel

After this whenever you right click any discord channel, server , member,etc. you will get an extra option to copy id .

So let's get our head back to whatever we started , now we get the id of welcome channel to what's next?

We will create a welcome channel id variable in our main file , like this,

 import discord  
 from discord.ext import commands, tasks  
 client = commands.Bot(command_prefix="-")  
 token = "YOUR TOKEN HERE"  
 welcome_channel_id= PASTE WELCOME CHANNEL ID HERE WITHOUT INVERTED COMMA  
 @client.event  
 async def on_ready():  
     print("bot is online!")  
 client.run(token)  

After this we will create an event named on_member_join , code :

 import discord  
 from discord.ext import commands, tasks  
 client = commands.Bot(command_prefix="-")  
 token = "YOUR TOKEN HERE"  
 welcome_channel_id= PASTE WELCOME CHANNEL ID HERE WITHOUT INVERTED COMMA  
 @client.event  
 async def on_ready():  
     print("bot is online!")  
 @client.event  
 async def on_member_join(member):  
   await client.wait_until_ready()  
   try:  
     channel = client.get_channel(WELCOME_CHANNEL_ID)  
     try:  
       embed = discord.Embed(colour = 0x05ffee )  
       embed.set_author(name = member.name,icon_url = member.avatar_url)  
       embed.set_image(url = "https://media.giphy.com/media/yyVph7ANKftIs/giphy.gif")  
       embed.add_field(name = "Welcome",value = f"**Hey,{member.mention}! Welcome to {member.guild.name}\n :star2: We hope you enjoy your stay here!\n :star2: Thanks for joining!\n :star2: We are very happy to have you!\n :star2: Don't forget to check out <#722005388492275805>'**",inline = False)  
       embed.set_thumbnail(url = "https://i.ibb.co/p3dqxcR/ezgif-com-video-to-gif.gif")  
       await channel.send(embed = embed)  
     except Exception as e:  
       raise e  
   except Exception as e:  
     raise e  
 client.run(token)  
What this code do, looks like this:
How to send welcome message with discord.py
Now, lets understand what we just did,
  • We created an event named on_member_join, what it do is whenever a new member joins the guild , it sends a message to the welcome channel we created earlier
  • we used an embed as our message , You can change url of set_image to whatever gif you want , you can even add a jpg or png there, its totally up to you.
  • I used my server's gif thumbnail , you can use your own.
  • I used this cyan  color which I really like you can reply that color's hex code by any other.
So , this is kind of very simple . You can create and modify this to much more . Still if you face any issues you can join my discord server and I will definitely solve your queries there or you can watch video tutorial on my youtube server. 

Links: Discord , Youtube

Alright this was all for this article , I hope you know now How to send welcome messages with discord.py bot
I will return with a new tutorial tomorrow,
Thanks for reading !
Bye!


Post a Comment

0 Comments