如何在所有行业中将消息广播到特定频道?

时间:2020-08-26 17:25:03

标签: python discord discord.py

我的机器人在它所在的每个服务器中都建立了一个名为OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 7 and format 'mpegts / MPEG-TS (MPEG-2 Transport Stream)' [ERROR:0] global /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-gi6lxw0x/opencv/modules/videoio/src/cap.cpp (563) open VIDEOIO(CV_IMAGES): raised OpenCV exception: OpenCV(4.4.0) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-gi6lxw0x/opencv/modules/videoio/src/cap_images.cpp:267: error: (-215:Assertion failed) number < max_number in function 'icvExtractPattern' 的频道。我想从服务器向所有名为quotient-private的频道广播一条消息,我编写了以下代码,该代码不会引发任何错误,但仍然无法正常工作

quotient-private

即使服务器所有者编辑了其名称,他们也可以通过任何方式获得此频道?

1 个答案:

答案 0 :(得分:0)

要找到正确的频道,可以在for循环中使用get()方法:

from discord.utils import get

@bot.command()
@commands.check(user_is_me)
async def broadcast(ctx, *, msg):
    for guild in bot.guilds:
        channel = get(guild.text_channels, name='quotient-private')
        if channel is not None:
            await channel.send(msg)

另外Channel.send_message()是旧的discord.py方法,现在您必须使用Channel.send()。随着discord.py rewrite更新(在v1.0之后),许多方法都发生了变化。
如果您对更改有困难,可以查看discord.py文档→Migrating to v1.0