python - 向服务器 discord.py 的所有成员发送 DM
问题描述
我正在尝试向服务器的所有成员发送 dm。我正在使用的代码没有错误,但它不起作用。
@bot.command(pass_context=True)
async def dm(ctx, *, message):
for user in ctx.guild.members:
try:
await user.send(message)
print(f"Sent {user.name} a DM.")
except:
print(f"Couldn't DM {user.name}.")
print("Sent all the server a DM.")
解决方案
我知道这已经得到了回答,但是对于将来看到这个的人来说:
- 确保您的机器人的意图允许它访问成员
- 还要记住一些成员关闭了 DM(来自服务器成员的 dms)
希望这会有所帮助
推荐阅读
- python - 通过 BeautifulSoup 从页面中获取 URL 列表和数据以及分页
- akeneo - Akeneo 中的产品资产和参考实体有什么区别?
- highcharts - 为类别 Highcharts 小部件中的任何元素创建链接
- php - 为什么我需要不断更新我的 Google 身份验证访问令牌?
- google-bigquery - BigQuery:如何根据轮班开始和结束时间查找一天中每个小时的工作员工数量
- javascript - How to set onkeypress or onkeydown only one time click?
- spring - Spring application on Tomcat configuration problem - error 404
- excel - How to create a unique identifier or equivalent to a dynamic table in Excel?
- angular - Why does angular tests fail sometimes?
- javascript - How can I take parameters from a url and append them to different tiles on the website?