Hello, Guys today we are gonna see How to Handel Events in Discord.py
What is An event
An Event is like which takes place when a person leaves/enters a server or a person's role changes or Someone boosts a server which is a rare thing I am joking but anyways jokes apart so basically what and all happens in a server is basically a sort of event so I will be listing all the events available in Discord.py
New member joins
import discord | |
from discord.ext import commands | |
bot = commands.Bot(command_prefix='!') | |
@bot.event | |
async def on_ready(): | |
print('Logged in as') | |
print(bot.user.name) | |
print(bot.user.id) | |
print('------') | |
@bot.event | |
async def on_member_join(member): | |
print(f"{member} has joined the server") | |
@bot.command() | |
async def hello(ctx): | |
await ctx.send('Hello Friend') | |
bot.run(" Your Discord Bot Token") |
Some person Leaves
import discord | |
from discord.ext import commands | |
bot = commands.Bot(command_prefix='!') | |
@bot.event | |
async def on_ready(): | |
print('Logged in as') | |
print(bot.user.name) | |
print(bot.user.id) | |
print('------') | |
@bot.event | |
async def on_member_remove(member): | |
print(f"{member} has left the server") | |
@bot.command() | |
async def hello(ctx): | |
await ctx.send('Hello Friend') | |
bot.run(" Your Discord Bot Token") |
Conclusion
Thanks For Reading my post till the end
Do Support me on Patreon - https://www.patreon.com/gogamic
Top comments (1)
Can you leave multiple @events on the same python file?