【问题标题】:How to send message to all servers discord py如何向所有服务器发送消息 discord py
【发布时间】:2020-10-26 08:05:36
【问题描述】:

嗨,我想做的是向我的机器人所在的所有服务器发送一条消息,这是我的代码,我很确定这不反对 tos,但如果是,请纠正我


await bot.wait_until_ready()
channels = []
for server in client.servers:
  for channel in server.channels:
     channels.append(channel)
      Message.send('HELLO! and thank you for adding this amazing bot. yes i am the owner ELONI sending this message saying thanks. thanks for getting us verified thanks for everythng. have a great DAY')

【问题讨论】:

    标签: python discord


    【解决方案1】:
    for guild in client.guilds: # guild stands for server
        for channel in guild.channels:
            if isinstance(channel, discord.TextChannel): # Check if channel is a text channel
                await channel.send("Hi")
    

    如果您使用 Discord.py-Rewrite,您可以将其添加到事件或命令中。

    示例事件:

    @client.event
    async def on_ready():
        for guild in client.guilds: # guild stands for server
            for channel in guild.channels:
                if isinstance(channel, discord.TextChannel): # Check if channel is a text channel
                    await channel.send("Hi")
    

    示例命令:

    
    @client.command()
    async def ping(ctx):
        for guild in client.guilds: # guild stands for server
            for channel in guild.channels:
                if isinstance(channel, discord.TextChannel): # Check if channel is a text channel
                    await channel.send("Hi")
    

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 2020-11-25
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 2021-06-02
      • 2021-06-17
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多