Discord.py质量dm机器人

时间:2018-03-15 02:05:25

标签: python-3.x discord discord.py

我一直试图找到一种方法来制作一个不和谐机器人dm我服务器内的每个人。我已经找到了一个类似于我的问题并尝试了答案,但它没有用。我目前的代码看起来像这样

  if message.content.upper().startswith('.MSG'):
      if "345897570268086277" in [role.id for role in message.author.roles]:
        member = discord.Member
        args = message.content.split(" ")
        if member == "@everyone":
          for server_member in server.members:
          await client.send_message(server_member, "%s" % (" ".join(args[1:])))

1 个答案:

答案 0 :(得分:0)

我会使用命令扩展名,而不是on_message

# import stuff we'll be using
from discord.ext import commands
from discord.utils import get

# Bot objects listen for commands on the channels they can "see" and react to them by 
# calling the function with the same name

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

# Here we register the below function with the bot Bot
# We also specify that we want to pass information about the message containing the command
# This is how we identify the author
@bot.command(pass_context=True) 
# The command is named MSG
# The `, *, payload` means take everything after the command and put it in one big string
async def MSG(ctx, *, payload):   
    # get will return the role if the author has it.  Otherwise, it will return None
    if get(ctx.message.author.roles, id="345897570268086277"): 
        for member in ctx.message.server.members:
            await bot.send_message(member, payload)

bot.run('token')

您对"345897570268086277"是角色ID有多确定?按名称搜索它可能更有意义。