Mass DM bot工作正常,现在不会发送消息 [英] Mass DM bot was working fine and now it wont send messages

查看:43
本文介绍了Mass DM bot工作正常,现在不会发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前,我与一个叫Diggy(来自这个社区)的家伙一起编码了MassDM机器人,作为我和一些朋友在BlackDesert Online上运行的行会.直到10月28日停止发送DM时,它的工作情况都还不错.一开始,它只是将DM发送给了具有指定角色的成员(105个中的3个)

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)

现在我更新了dicord.py,它不会将消息发送给任何人(有时仅发送给其中一个,或者两个...是随机的)...

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

该不和谐服务器中有105个用户,角色为"Miembros" ...

There are 105 users in that discord server with the role "Miembros"...

这是代码...

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

曾经阅读过文档并试图理解如何解决它,但是我想我对python的了解还很差.感谢您的帮助.

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.

推荐答案

我不确定,但是您的问题可能是由于Intents引起的.在新版本的discord.py(1.5.x)中,有一些关于 Intents 的更新.意图类似于权限,您必须对其进行定义以获取频道,成员和某些事件等.必须在定义 bot = discord.Bot(prefix ='').之前对其进行定义.

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)

如果要获取有关Intent的更多信息,可以查看

If you want to get more information about Intents, you can look at the API References.

这篇关于Mass DM bot工作正常,现在不会发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆