问题描述
几个月前,我和一个叫 Diggy 的人(来自这个社区)为我和一些朋友在 BlackDesert Online 上运行的公会编写了一个 MassDM 机器人.它工作得很好,直到 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)...
discord 服务器中有 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
的更新.Intents 类似于权限,你必须定义它来获取频道、成员和一些事件等.你必须在定义 bot = discord.Bot(prefix='')
之前定义它.p>
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)
如果你想获取更多关于 Intents 的信息,可以查看 API 参考.
If you want to get more information about Intents, you can look at the API References.
这篇关于Mass DM 机器人工作正常,现在它不会发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!