我想实现一个很酷的广播命令。该命令将是这样的。如果管理员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:这就像“说”命令,但它会将它发送到指定的频道。
1 回答
千巷猫影
TA贡献1829条经验 获得超7个赞
Client.get_channel即使您没有对服务器的引用,也可以使用它来解析通道。我在下面假设您始终希望将消息发送到特定的渠道,无论它来自何处。
不和谐还对仅关键字参数进行了特殊处理,使它们能够捕获消息的其余未处理文本,而不是拆分为参数。在你的榜样,bc(args, message),message只会捕捉单个词或强迫你在引号来包装消息。
@bot.command(pass_context=True)
async def bc(ctx, *, message):
channel = bot.get_channel("474316889435275264")
await bot.send_message(channel, message)
添加回答
举报
0/150
提交
取消
