【发布时间】:2021-05-03 02:28:48
【问题描述】:
如何同时向 Discord 服务器中的每个频道发送消息?
我在另一篇文章中使用了此代码,但在运行命令时没有收到任何响应。
@client.command(pass_context=True)
async def broadcast(ctx, *, msg):
for guild in bot.guilds:
for channel in guild.channels:
try:
await bot.send_message(channel, msg)
except Exception:
continue
else:
break
【问题讨论】:
-
欢迎来到 Stackoverflow。在
except块中添加一些print语句以查看是否有任何问题是有意义的。 -
您的命令有
@client.command(),但您在函数中使用了bot.guilds。请根据您的定义仅使用一个。 -
我稍微摆弄了一下,最后得到了这个错误:raise MissingRequiredArgument(param) discord.ext.commands.errors.MissingRequiredArgument: msg is a required argument that is missing.
-
那是因为你没有传递任何消息
-
另外,你为什么用
else?
标签: python discord discord.py