問題描述
幾個月前,我和一個叫 Diggy 的人(來自這個社區(qū))為我和一些朋友在 BlackDesert Online 上運行的公會編寫了一個 MassDM 機器人.它工作得很好,直到 10 月 28 日停止發(fā)送 DM.一開始它只是將 DM 發(fā)送給一些具有指定角色的成員(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)
現(xiàn)在我更新了 dicord.py,它不會將消息發(fā)送給任何人(有時只發(fā)送給其中一個,或者兩個...有點隨機)...
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 服務(wù)器中有 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) 中,有一些關(guān)于 Intents
的更新.Intents 類似于權(quán)限,你必須定義它來獲取頻道、成員和一些事件等.你必須在定義 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)
如果你想獲取更多關(guān)于 Intents 的信息,可以查看 API 參考.
If you want to get more information about Intents, you can look at the API References.
這篇關(guān)于Mass DM 機器人工作正常,現(xiàn)在它不會發(fā)送消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!