[英]How can I only DM users with a certain role in discord.py?
I want the bot to dm to members having a certain role so i tried this,我希望机器人将 dm 发送给具有特定角色的成员,所以我尝试了这个,
@bot.command(pass_context=True)
async def message_role(ctx, role: discord.Role, *, message):
for member in ctx.message.server.members:
if role in member.roles:
await member.send(member, message)
It doesn't work actually and I also don't want my bot to be flagged for spamming so I want a check or something so that the bot will only dm if the role has 25 or below 25 members.它实际上不起作用,我也不希望我的机器人被标记为垃圾邮件,所以我想要一张支票或其他东西,这样机器人只会在角色有 25 名或低于 25 名成员时发送邮件。 If the role have more than 25 users it should return and say something like - "Can't dm this much users".如果角色有超过 25 个用户,它应该返回并说类似 - “不能 dm 这么多用户”。 Thanks!谢谢!
You can check the length of role.members
您可以检查role.members
的长度
@bot.command()
async def message_role(ctx, role: discord.Role, *, message):
if not len(role.members) <= 25:
return await ctx.send("Can't dm this much users")
for i in role.members:
await i.send(message)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.