discord.py中的广播命令

我想实现一个很酷的广播命令。该命令将是这样的。如果管理员DM与机器人一起$bc <whatever they want to type here>进行攻击,则机器人会将消息发送到#broadcast。它可以从 DM 和服务器读取。我尝试了此命令,但它没有按照我的想法工作。


@bot.command(pass_context=True)

async def bc(args, message):

    channel = server.get_channel("474316889435275264")

    await bot.send_message(channel, args)

它无法读取任何内容, channel = server.get_channel("474316889435275264") 所以我知道代码是错误的。


PS:这就像“说”命令,但它会将它发送到指定的频道。


鸿蒙传说
浏览 188回答 1
1回答

千巷猫影

Client.get_channel即使您没有对服务器的引用,也可以使用它来解析通道。我在下面假设您始终希望将消息发送到特定的渠道,无论它来自何处。不和谐还对仅关键字参数进行了特殊处理,使它们能够捕获消息的其余未处理文本,而不是拆分为参数。在你的榜样,bc(args, message),message只会捕捉单个词或强迫你在引号来包装消息。@bot.command(pass_context=True)async def bc(ctx, *, message):&nbsp; &nbsp; channel = bot.get_channel("474316889435275264")&nbsp; &nbsp; await bot.send_message(channel, message)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python