Answers for "discord.py events"

4

command handler discord.py

for file in os.listdir("./cogs"): # lists all the cog files inside the cog folder.
    if file.endswith(".py"): # It gets all the cogs that ends with a ".py".
        name = file[:-3] # It gets the name of the file removing the ".py"
        bot.load_extension(f"cogs.{name}") # This loads the cog.
Posted by: Guest on July-03-2021
1

on member leave event in discord.py

@client.event
async def on_member_leave(member):
    print("member has left a server.")
Posted by: Guest on July-29-2021
4

on message discord py

@bot.event
async def on_message(message):
    if message.content == "pong":
        await message.channel.send('ping')
Posted by: Guest on January-12-2021
3

discordpy base code

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('Logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run('your token here')
Posted by: Guest on July-15-2020
1

get guild from a channel discord py

channel.guild
Posted by: Guest on January-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language