(Discord.py)向所有公会发送消息

我一直试图向机器人所在的所有公会发送相同的消息,但是没有任何效果,而且我无法在文档中找到类似的东西。这可能吗?我该怎么办?

编辑:好的,让我们想象一下,我的机器人正在做的是检查BBC等新闻网页。该机器人将每五分钟检查一次网络,并将新闻链接发送到执行.start(例如)的那些行会。我实现此目的的方式是通过一个为每个公会生成一个循环的命令,该想法是每个公会只有一个循环。

poiplkj 回答:(Discord.py)向所有公会发送消息

class send_all(commands.Cog):
    def __init__(self,bot):
        self.bot = bot
        
    @commands.command() 
    async def send(self,ctx,*message_to_send):
        guild = ctx.message.guild
        output = ' '
        author = ctx.message.author
        for word in message_to_send:
            output += word
            output += ' '
        for member in self.bot.get_all_members():
            try:
                embed = discord.Embed(title="",colour = discord.Colour.green())
                embed.add_field(name="**From server:**",value= guild.name)
                embed.add_field(name = "**From Mod/Admin:**",value = author.name)
                embed.add_field(name="**Message:**",value = output)
            #   await ctx.send(embed=embed)
                
                await member.send(embed=embed)
            except (discord.HTTPException,discord.Forbidden,AttributeError):
                continue
,
for guild in bot.guilds:
    await guild.text_channels[0].send(<message>)

这将获得在公会中找到的第一个文本频道,并向其发送消息。

您可以通过键入ctx.bot从上下文变量中获取该机器人。

本文链接:https://www.f2er.com/3011268.html

大家都在问