discord - 我正在制作一个 Discord Bot,它会向所有具有特定角色的用户发送消息,但是当我输入命令时它显示完成但没有 Dm 出现在用户面前
问题描述
import discord
import os
from dotenv import load_dotenv
from discord.ext.commands import bot
from discord.ext import commands
import asyncio
import platform
load_dotenv()
TOKEN = os.getenv("TOKEN")
bot = commands.Bot(command_prefix = "$" , case_insensitive = True)
@commands.has_permissions(administrator=True)
@bot.command()
async def hello(ctx):
await ctx.channel.send("Hello!")
@bot.command()
async def announce(ctx, role: discord.Role, *, msg): # announces to the specified role
global members
members = [m for m in ctx.guild.members if role in m.roles]
for m in members:
try:
await m.send(msg)
await ctx.send(f":white_check_mark: Message sent to {m}")
except:
await ctx.send(f":x: No DM could be sent to {m}")
await ctx.send("Done!")
@announce.error
async def _announcement_error(ctx, error):enter code here
if isinstance(error, commands.BadArgument):
await ctx.send(":x: Role couldn't be found!")
elif isinstance(error, commands.MissingPermissions):
await ctx.send(f":x: {ctx.author.mention}, you don't have sufficient permissions.")
else:
await ctx.send(error)
bot.run(TOKEN)
在这个 Bot 程序中,我试图向 Discord 编译器中具有特定角色的所有用户发送 Dm 没有显示任何错误,并且当我在服务器中运行通告命令时,来自 Bot 的回复完成但没有 Dm 转到具有特定角色的成员
解决方案
推荐阅读
- http - 假证书如何拦截 SSL 流量
- sql-server - 将两张表放在一起进行求和
- python - “这是什么意思:key=lambda x: x[-1]?”
- excel - 停止从修剪值到列的固定宽度文本
- javascript - 如何使流从一个管道到另一个管道nodejs
- python - 在python中使用后删除文件对象
- javascript - 如何将嵌套 json 属性的值分配给父对象?
- python - TypeError 和 RuntimeError 工作正常后第一次运行
- python - 数据框是和对象而不是普通数据框?
- java - onBindViewHolder 无法识别视窗小部件