1
votes

Im setup discord welcome bot, on python, and this is the error:

File "welcome-bot.py", line 27, in on_member_join await client.send_message(member, newUserMessage) AttributeError: 'Client' object has no attribute 'send_message'

import discord
import asyncio

client=discord.Client()

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

newUserMessage = """
is
that
works?
"""

@client.event
async def on_member_join(member):
    print("Recognised that a member called " + member.name + " joined")
    await client.send_message(member, newUserMessage)
    print("Sent message to " + member.name)```
1
Well, um... this is it: instances of the class Client do not have this attribute. You should consult the documentation for this library to find out which methods this class provides.ForceBru

1 Answers

0
votes

Client does not contain a function called send_message where you can PM/DM a user.

Instead you can fetch the dm_channel property from the member that joined, and send a message in that channel:

joinedUserDM = member.dm_channel

if joinedUserDM is None:
    await member.create_dm()
    joinedUserDM = member.dm_channel

joinedUserDM.send("message to send to the joined user's private inbox")