问题
i coded a MassDM bot with a guy called Diggy (from this community) few months ago, for a guild that I and some friends run on BlackDesert Online. It was working just fine till October 28th when stopped sending the DMs. At the begining it just sent the DM to some members that had the specified role (3 out of 105)
and now that I updated dicord.py, it sends the message to no one (and sometimes to just one of them, or two... is kinda random)...
There are 105 users in that discord server with the role "Miembros"...
Here is the code...
bot = commands.Bot(command_prefix="+", case_insensitive=True)
bot.remove_command("help")
@commands.has_permissions(administrator=True)
@bot.command()
async def announce(ctx, role: discord.Role, *, msg):
if ctx.channel.id == 708458959991865354:
members = [m for m in ctx.guild.members if role in m.roles]
count = 0
for m in members:
try:
await m.send(msg)
await ctx.send(f":white_check_mark: Mensaje enviado a {m}")
count += 1
except:
await ctx.send(f":x: No se pudo enviar el mensaje a {m}!")
await ctx.send(f"Hecho! {count} miembro{'' if count == 1 else 's'} notificados de un total de {len(members)}")
else:
await ctx.send("Este comando no esta permitido en este canal.")
bot.run("...")
Been reading the documentation and trying to understand how to solve it, but I guess my knowledge in python is pretty poor. Thanks for the help.
回答1:
I'm not sure but your problem is probably because of Intents. In the new version of discord.py(1.5.x), there're some updates about Intents
. Intents are similar to permissions, you have to define it to get channels, members and some events etc. You have to define it before defining the bot = discord.Bot(prefix='')
.
import discord
intents = discord.Intents().all()
bot = discord.Bot(prefix='', intents=intents)
If you want to get more information about Intents, you can look at the API References.
来源:https://stackoverflow.com/questions/64619897/mass-dm-bot-was-working-fine-and-now-it-wont-send-messages