Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

python - Mass DM bot was working fine and now it wont send messages

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)

enter image description here

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)...

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...