0
    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 转到具有特定角色的成员

4

0 回答 0