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.
bot.get_all_members()
is probably causing that error. You can get the members withctx.guild members
. So you can do this:And also I added
asyncio.sleep()
because as I know,time.sleep()
blocks all the code so don't forget to import it.