如何同时向 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
答案 0 :(得分:1)
您在某些地方使用了 create_app()
,在其他地方使用了 client
,更多的是此代码效率不高,因为在调用它时不需要遍历公会仅来自一台服务器,这会导致多台服务器中的垃圾邮件。我还注意到您正在使用旧版 bot
中的函数。尝试改用这个:
discord.py