Bot dm de masse Discord.py
J'ai essayé de trouver un moyen de créer un bot discord dm tout le monde à l'intérieur de mon serveur. J'ai déjà trouvé une question similaire à la mienne et j'ai essayé la réponse mais cela n'a pas fonctionné. Mon code actuel ressemble à ceci
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:])))
Solution du problème
J'utiliserais l'extension de commandes pour cela, pason_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')
Êtes-vous sûr qu'il "345897570268086277"
s'agit de l'identifiant du rôle ? Il serait peut-être plus judicieux de le rechercher par son nom.
Commentaires
Enregistrer un commentaire