1
1
132eee2021-01-10 15:14:24
Python
132eee, 2021-01-10 15:14:24

How to force a bot to write on a specific channel?

I want to create a reporting system for a discord bot. I want him to write on channels called "report".
So far here is the whole team:

@bot.command(pass_context=True)
async def репорт(ctx, arg, *, arg2):
    embed=discord.Embed(title="Report")
    embed.add_field(name="Пользователь:", value= arg , inline=True)
    embed.add_field(name="Причина:", value= arg2 , inline=True)
    await ctx.send(embed=embed)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
retUrn3d, 2021-01-10
@132eee

To do this, it is enough to get the channel itself in order to send something to it.
This is easy to do with: bot.get_channel(id_here)
But your task is to send a message to a channel called: "report".
To do this, we must go through all the channels on our server and find them with the name we need.

for channel in ctx.guild.channels:
        if channel.name == "report":
            #Объект канала, который мы будем использовать для отправки сообщения.
            channel = bot.get_channel(channel.id)

Finally, your code should look like this.
@bot.command(pass_context=True)
async def report(ctx, *, arg):
    emb = discord.Embed(title="REPORT", description=f"От пользователя {ctx.author.mention}", colour=discord.Color.red())
    emb.add_field(name="Причина:", value=arg, inline=True)
    # Получаем все каналы в нашей гильдии.
    for channel in ctx.guild.channels:
        if channel.name == "report":
            # Объект канала, который мы будем использовать для отправки сообщения.
            channel = bot.get_channel(channel.id)
            # Отправляем сообщение в нужный нам канал.
            await channel.send(embed=emb)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question