So i want that the bot dms the server owner when it get added to the server.
Here is the code:
@client.event
async def on_guild_join(guild, ctx):
guild_owner = client.get_user(int(ctx.guild.owner.id))
await guild_owner.send("hi")
But I always get this one error:
TypeError: on_guild_join() missing 1 required positional argument: 'ctx'
I know what that means but i dont know how to fix that.
CodePudding user response:
I don't know if this relates to you but you can check this guys answer to a similar question stackoverflow flow answer
CodePudding user response:
First of all, as mousetail has said, on_guild_join
only takes one argument. You should only have guild
as the function's argument. Secondly, since you're using a guild
object, you should already be able to access the guild's owner through guild.owner
. Do view the revised code below.
@client.event
async def on_guild_join(guild):
try:
await guild.owner.send("I'm now in your server!")
except: # occurs if your bot cannot send dm to the owner
print(f"{guild.owner} has their dms turned off")