Send message to specific text channel by name not ID in a Python Discord Bot

前端 未结 1 1203
闹比i
闹比i 2020-12-06 23:12

Is there an equivalent command to client.get_channel(\'ID\') that allows you to send the message to a specifically named text channel.

My project is a report system

相关标签:
1条回答
  • 2020-12-06 23:52

    You can use discord.utils.get to iterate through server.channels and find the channel with a particular name:

    import discord
    from discord.utils import get
    
    async def report(server, name, *args, **kwargs):
        channel = get(server.channels, name=name, type=discord.ChannelType.text)
        await bot.send_message(channel, *args, **kwargs)
    
    0 讨论(0)
提交回复
热议问题