通过名称而不是Python Discord Bot中的ID将消息发送到特定的文本通道

时间:2018-09-06 21:19:07

标签: python-3.x discord.py

client.get_channel('ID')是否存在等效命令,可用于将消息发送到专门命名的文本通道。

我的项目是一个报告系统,它将在所有员工都可以看到的员工聊天中打印报告。我希望它可以在多台服务器上使用,所以不能选择使用ID,因为所有服务器都具有不同的通道ID。

1 个答案:

答案 0 :(得分:2)

您可以使用discord.utils.get遍历server.channels并找到具有特定名称的频道:

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)