Discord.py: Welcome/Leave

Created on 8 Feb 2018  路  7Comments  路  Source: Rapptz/discord.py

Because it does not work ?

import discord
import asyncio
import random

client = discord.Client()

@client.event
async def on_ready():
    print('BOT')
    print(client.user.name)
    print(client.user.id)
    print('---------------')

@client.event
async def on_member_join(member):
    serverchannel = member.server.default_channel
    msg = "Willkommen {0} auf {1}".format(member.mention, member.server.name)
    await client.send_message(serverchannel, msg)


@client.event
async def on_member_remove(member):
    serverchannel = member.server.default_channel
    msg = "Bye Bye {0}".format(member.mention)
    await client.send_message(serverchannel, msg)


client.run('token')

Most helpful comment

.send_message(member,content)

All 7 comments

Default channels are defunct as of some time ago, they no longer work due to discord removing them. Obtain a destination through some other means, usually by having a user set it and retrieving it with client.get_channel

how can I send to the user's DM then?

.send_message(member,content)

I can also use,
channel = discord.Object("id-channel")
to set the channel that will display msg?

Sure, but it's better to just use client.get_channel.

one last question on the subject, how do I mention a server channel in the user's DM?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MrBrahm picture MrBrahm  路  3Comments

synbitz picture synbitz  路  3Comments

PicklesJars picture PicklesJars  路  3Comments

Rimmy50 picture Rimmy50  路  3Comments

reuscam picture reuscam  路  3Comments