1

Someone asked me to make a bot for him that sends a DM to anyone he specifies through a command, like *send_dm @Jess#6461 hello.

I've searched alot and I came across this code:

async def send_dm(ctx,member:discord.Member,*,content):
    await client.send_message(member,content)

but then I got the error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'send_message'

I want to type for example : *send_dm @Jess#6461 hello and the bot sends a DM saying "hello" to that user.

wotman
  • 45
  • 1
  • 2
  • 9

3 Answers3

6

client.send_message() has been replaced by channel.send() in the version 1 of discord.py

You can use Member.create_dm() to create a channel for sending messages to the user

async def send_dm(ctx, member: discord.Member, *, content):
    channel = await member.create_dm()
    await channel.send(content)
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50
0

HI there hope this help you

client.command(aliases=['dm'])
async def DM(ctx, user : discord.User, *, msg):
    try:
        await user.send(msg)
        await ctx.send(f':white_check_mark: Your Message has been sent')
    except:
        await ctx.send(':x: Member had their dm close, message not sent')

change you client if you use any other str

0

The easiest way to do is:

async def send_dm(ctx,member:discord.Member,*,content):
  await member.send(content)