F
F
flameyolo2021-06-17 21:28:07
Python
flameyolo, 2021-06-17 21:28:07

Sending messages to a channel by name, not ID // discord.py?

Hello everyone, I want to send moderation logs to a separate channel without specifying the ID of the log channel.

those. not like this:
logshannel = bot.get_channel( conditional log channel ID ) # LOG CHANNEL ID

and something like this:
logschannel = bot.get_channel( channel name ) # LOG CHANNEL NAME

The code itself:

@bot.command()
@commands.has_permissions(administrator=True)
async def kick(ctx, member:discord.Member, reason):
    channel = bot.get_channel(************) # ID КАНАЛА ЛОГОВ
    embed = discord.Embed( color=0xff0000, title='Kick')
    embed.add_field(name='Модератор', value=ctx.message.author.mention)
    embed.add_field(name='Пользователь', value=member.mention)
    embed.add_field(name='Причина', value=reason)
    await member.kick()
    await ctx.send(embed=embed)
    await channel.send(embed=embed)


Required for use on multiple servers. I do this because the databases at my level are too complex.
Is it feasible? If so, how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
flameyolo, 2021-06-18
@flameyolo

I found a solution by typing, if someone needs it:

channel = discord.utils.get(ctx.guild.channels, name='moderation-logs') # НАЗВАНИЕ КАНАЛА ЛОГОВ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question