0

So, I was making a custom bot for my server and had a problem, heres my code:

@bot.command()
@commands.has_role('| Owner')
async def dmall(ctx,desc):
    title = f'message from {ctx.message.author}'
    await ctx.send('Sending messages!')
    for members in bot.get_all_members():
        embed = discord.Embed(title=title, description=desc)
        await members.send(embed=embed)
        print('Sent a message!')
        time.sleep(3)

The error i get:

Ignoring exception in command dmall:
Traceback (most recent call last):
  File "/home/container/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/container/main.py", line 37, in dmall
    await members.send(embed=embed)
  File "/home/container/discord/abc.py", line 864, in send
    channel = await self._get_channel()
  File "/home/container/discord/member.py", line 250, in _get_channel
    ch = await self.create_dm()
  File "/home/container/discord/member.py", line 110, in general
    return getattr(self._user, x)(*args, **kwargs)
AttributeError: 'ClientUser' object has no attribute 'create_dm'

I have been trying to figure it out, the thing is im not using create_dm anywhere in my code.

MysteriousK
  • 89
  • 1
  • 3
  • 9

1 Answers1

0

bot.get_all_members() is probably causing that error. You can get the members with ctx.guild members. So you can do this:

@bot.command()
@commands.has_role('| Owner')
async def dmall(ctx,desc):
    title = f'message from {ctx.message.author}'
    await ctx.send('Sending messages!')
    for member in ctx.guild.members:
        embed = discord.Embed(title=title, description=desc)
        await member.send(embed=embed)
        print('Sent a message!')
        await asyncio.sleep(3)

And also I added asyncio.sleep() because as I know, time.sleep() blocks all the code so don't forget to import it.

Nurqm
  • 4,715
  • 2
  • 11
  • 35
  • ```Ignoring exception in command dmall: Traceback (most recent call last): File "/home/container/discord/ext/commands/core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "/home/container/main.py", line 38, in dmall await member.send(embed=embed) File "/home/container/discord/abc.py", line 864, in send channel = await self._get_channel() File "/home/container/discord/member.py", line 250, in _get_channel ch = await self.create_dm() AttributeError: 'ClientUser' object has no attribute 'create_dm'``` – MysteriousK Oct 01 '20 at 11:24
  • Can you try to send a normal message, not an embed? – Nurqm Oct 01 '20 at 12:01