Бот видит только себя
Я хочу сделать бота который рассылает сообщения всем участникам гильдии(сервера)
import discord
import asyncio
from discord.ext.commands import Bot
from discord import DMChannel
# Доставание токена из файла
token = open('token.txt', 'r').readline()
prefix = ('m!')
bot = Bot ( command_prefix = prefix )
bot.remove_command('help')
@bot.event
async def on_ready():
print(f"Бот подключен к {bot.user}")
# статус и действие
await bot.change_presence( status= discord.Status.idle, activity= discord.Streaming(name= 'c!help', colour= discord.Color.red(), url= 'https://www.twitch.tv/ftnl') )
memb = 'a'
@bot.command(pass_context=True)
async def dm(ctx, message):
guild = ctx.message.guild
for guild in bot.guilds:
for member in ctx.guild.members:
channel = bot.get_channel(id=774631399478394890)
await channel.send(f"m!a {member.mention} {message}")
@bot.command()
async def a(ctx, member: discord.Member, *, message):
member.send( message )
# Запуск бота
bot.run( token )
извините что так холтурно сделал, но когда я делаю по другому, тип так:
import discord
import asyncio
from discord.ext.commands import Bot
from discord import DMChannel
# Доставание токена из файла
token = open('token.txt', 'r').readline()
prefix = ('m!')
bot = Bot ( command_prefix = prefix )
bot.remove_command('help')
@bot.event
async def on_ready():
print(f"Бот подключен к {bot.user}")
# статус и действие
await bot.change_presence( status= discord.Status.idle, activity= discord.Streaming(name= 'c!help', colour= discord.Color.red(), url= 'https://www.twitch.tv/ftnl') )
@bot.command(pass_context=True)
async def dm(ctx, message):
for member in ctx.guild.members:
await member.send(message)
# Запуск бота
bot.run( token )
то появляется ошибка:
C:\Users\User\Desktop\messages>python mes.py
Бот подключен к Send#3893
Ignoring exception in command dm:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "mes.py", line 24, in dm
await member.send(message)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\abc.py", line 864, in send
channel = await self._get_channel()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\member.py", line 250, in _get_channel
ch = await self.create_dm()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\member.py", line 110, in general
return 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\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\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'
Ответы (1 шт):
Автор решения: SNVMK
→ Ссылка
Измени комманду на примерно такое:
for member in ctx.guild.members:
try:
await member.send(message)
except:
continue
