Skip to content

Instantly share code, notes, and snippets.

@0xicl33n
Last active November 23, 2023 19:02
Show Gist options
  • Save 0xicl33n/e5008c5865347aafc644a67455507314 to your computer and use it in GitHub Desktop.
Save 0xicl33n/e5008c5865347aafc644a67455507314 to your computer and use it in GitHub Desktop.
discord.py rewrite send message when bot joins server
@bot.event
async def on_guild_join(guild):
for channel in guild.text_channels:
if channel.permissions_for(guild.me).send_messages:
await channel.send('Hey there! this is the message i send when i join a server')
break
@W1L7dev
Copy link

W1L7dev commented Jul 12, 2021

so i've changed the code to work with my bot but it errors
Ignoring exception in on_guild_join Traceback (most recent call last): File "D:\The_f\python\lib\site-packages\discord\client.py", line 333, in _run_event await coro(*args, **kwargs) TypeError: on_guild_join() takes 1 positional argument but 2 were given
the code that i used was
`import discord
from discord.ext import commands

class role(commands.Cog):

def __init__(self, client):
    self.client = client

@commands.Cog.listener()
async def on_guild_join(guild):
    for channel in guild.text_channels:
        if channel.permissions_for(guild.me).send_messages:
            await channel.send(f'Hey there! do `{prefix}setup` to make your moderation role')
        break

def setup(client):
client.add_cog(role(client))`
any ideas on how to fix it?

Just add "self" before guild at line 9

@akionsight
Copy link

i doesnt work for me, i dont get even a error message.....
i'Ve enabled intents.guilds = True

maybe cuz the library (discord.py) is now dead

@Leksa1234
Copy link

i doesnt work for me, i dont get even a error message.....
i'Ve enabled intents.guilds = True

maybe cuz the library (discord.py) is now dead

hmmmm me is work how you not work?

@Parad1se-py
Copy link

Yes, possible. Try the new library "Py-Cord" and go through their docs, it's pretty similar to DPY but Py-Cord is what I recommend to use now, after all, discord.py is discontinued.

@akionsight
Copy link

@0xicl33n the thing is that, this gist is just super super useful

@BitcoinJake09
Copy link

@0xicl33n the thing is that, this gist is just super super useful

i agree, im using discord.py still and was trying to figure this out exactly lmao, very helpful indeed <3

@YbicG
Copy link

YbicG commented Sep 21, 2022

@0xicl33n Bro you commented though?

@Thecode764
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment