V
V
vlan3ik2021-08-27 11:56:43
Python
vlan3ik, 2021-08-27 11:56:43

How to send a mailout to all servers that have a bot?

@bot.command(aliases = ['рассылка',"р","ссылка"])
async def rassilka(ctx ):
    if ctx.author.id == мой id:
        embed = discord.Embed(title="",description=f"", colour=discord.Colour.blue())
        embed.add_field(name=f"", value="", inline=True)
        for guild in bot.guilds:
            print(f"{guild} - not ready")
            random_chan = guild.channels
            chenel = random.choice(random_chan)
            await chenel.send("Срочная инфа")
            await chenel.send(embed  =embed)
            print(f"{guild} - ready")


Here is my code now
An example of an error, but the errors always come out different
Command raised an exception: AttributeError: 'CategoryChannel' object has no attribute 'send'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Renat Ataev, 2021-08-27
@vlan3ik

You were clearly pointed out in the error. AttributeError: 'CategoryChannel' object has no attribute 'send' , i.e. The "CategoryChannel" object does not contain a "send" attribute. The guild.channels variable contains the channel categories. You need to get text channels from the category.

@bot.command(aliases = ['рассылка',"р","ссылка"])
async def rassilka(ctx ):
    if ctx.author.id == мой id:
        embed = discord.Embed(title="",description=f"", colour=discord.Colour.blue())
        embed.add_field(name=f"", value="", inline=True)
        for guild in bot.guilds:
            print(f"{guild} - not ready")
            random_chan = [ch for ch in guild.channels if ch.type == discord.ChannelType.text]
            chenel = random.choice(random_chan)
            await chenel.send("Срочная инфа")
            await chenel.send(embed  =embed)
            print(f"{guild} - ready")

Just don't forget to import discord at the beginning of the code or it will throw an error!!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question