Answer the question
In order to leave comments, you need to log in
Discord.py code error what to do?
Code error:
intents = discord.Intents.default()
intents.members = True
client=commands.Bot(intents=intents, command_prefix = ".")
client.remove_command('help') # удаляем встроенную команду хелпа
@client.command()
async def news(ctx):
guild = ctx.guild
async for member in guild.fetch_members(limit=None):
await member.send("Приветики!")
print("Отправил", member)
Ignoring exception in command news:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Admin\Desktop\bethce\anti-lavan-new.py", line 129, innews
await member.send("Приветики!")
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1013, in send
channel = await self._get_channel()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 299, in _get_channel
ch = await self.create_dm()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 142, in general
return await getattr(self._user, x)(*args, **kwargs)
AttributeError: 'ClientUser' object has no attribute 'create_dm'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'create_dm'
Answer the question
In order to leave comments, you need to log in
Judging by the error, the bot is trying to get PM with itself.
Need to check if the person you want to send a message to is your bot:
@client.command()
async def news(ctx):
guild = ctx.guild
async for member in guild.fetch_members(limit=None):
if member != client.user:
await member.send("Приветики!")
print("Отправил", member)
@client.command()
async def news(ctx):
guild = ctx.guild
async for member in guild.fetch_members(limit=None):
if not member.bot:
await member.send("Приветики!")
print("Отправил", member)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question