简体   繁体   English

如何在discord.py中仅DM具有特定角色的用户?

[英]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.

相关问题 如何检查消息作者的角色 + 如何在 Discord.py 上 DM 特定角色? - How can I check the role of a message author + How do I DM specific roles on Discord.py? Python:我如何使用光而不是 discord.py DM 加入 discord 服务器的用户 - Python: How can I DM users that joins discord server using hikari not discord.py 如何在discord.py中DM所有用户 - How to DM all users in discord.py 如果用户向机器人发送密码短语 discord.py,如何获得 discord 机器人以赋予用户特定角色 - How to get a discord bot to give a user a certain role if they DM the bot a passphrase discord.py 如何仅在 discord.py 中制作此命令 DM? - How do I make this command DM only in discord.py? 在 discord.py 中只向特定服务器的用户发送欢迎 DM - Only send welcome DM to users of specific server in discord.py Discord.py - 我的 discord.bot 如何在特定时间向某人发送消息? - 解决方案在这里 - Discord.py - how can my discord.bot dm message to someone at certain time? - Solution here Discord.py 如何测试成员在角色字典中是否具有特定角色? - Discord.py how can I test if a member has certain role in a dictionary of roles? 如何在#channel 中显示具有特定角色的成员? (使用discord.py) - how can I display in the #channel, members with a certain role? (with discord.py) 如何从数组 discord.py 对用户进行 dm - How to dm users from an array discord.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM