【问题标题】:How to message everyone in a discord server with a certain role如何以特定角色向不和谐服务器中的每个人发送消息
【发布时间】:2018-04-06 04:14:27
【问题描述】:

我正在寻找一种方法,使用具有特定角色的 discord.py 向不和谐服务器中的每个人发送消息,并使用我选择的自定义消息(预选)我尝试了许多不同的方法,但都没有奏效。请帮帮我!

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

遍历Server上的所有Members,并检查它们是否具有指定的角色。

from discord.ext import commands
import discord

bot = commands.Bot(command_prefix='!')

@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 bot.send_message(member, message)

bot.run('TOKEN')

这会像这样被调用

!message_role messageable Hi everybody!

这会将Hi everybody! 发送给具有messageable 角色的所有人。

【讨论】:

  • 我收到此错误 discord.ext.commands.errors.CommandInvokeError: 命令引发异常:Att ributeError: 'Context' object has no attribute 'server'
  • 糟糕,应该是ctx.message.server 我将编辑我的答案
猜你喜欢
  • 2020-08-16
  • 2019-06-25
  • 2020-03-13
  • 2020-08-20
  • 2021-01-19
  • 2018-12-09
  • 2020-12-18
  • 2021-08-16
  • 2021-06-22
相关资源
最近更新 更多