0

hello i have been trying to edit this code to get it to work but im stuck at a point where ive been getting this error:

File "main.py", line 24, in on_member_join
    await client.send_message(member, DMMessage)
AttributeError: 'Client' object has no attribute 'send_message'

i assume this has something to do with the intents but after lots of research and time i haven't been able to fix it could someone explain to me how i can fix this?

my code for reference:

import discord

import os

intents = discord.Intents(members=True, messages = True, guilds=True,)



client = discord.Client(intents=intents)

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

DMMessage = "hello"

@client.event
async def on_member_join(member):
    print("Recognized that " + member.name + " joined")
    await client.send_message(member, DMMessage)
    await client.send_message(discord.Object(id='77769000355535264'), 'Welcome!')
    print("Sent message to " + member.name)
    print("Sent message about " + member.name + " to the server")

@client.event
async def on_member_remove(member):
    print("Recognized that " + member.name + " left")
    await client.send_message(discord.Object(id='77769000355535264'), '**' + member.mention + '** just left.')
    print("Sent message to server")


client.run(os.getenv('TOKEN'))

1 Answer 1

1

Client.send_message() is a very outdated method and has been removed in the latest versions of discord.py. Use Member.send() to send DM messages:

@client.event
async def on_member_join(member):
    await member.send('Welcome to the server!')

Also note that when a member leaves the server and the bot has no common guilds with that user, your bot will be unable to DM them and will throw a discord.Forbidden exception.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.