【问题标题】:Discord.py Sending a message to specific guilds using webhooksDiscord.py 使用 webhook 向特定公会发送消息
【发布时间】:2020-11-16 14:42:37
【问题描述】:

所以我的服务器决定开始这场比赛,为了与其他所有服务器通信,我们想创建一个命令,我们可以使用他们发送过来的 webhook 并使用它来传达信息。 示例:

Server1Webhook = "webhook url"

Server2Webhook = "webhook url"

Server3Webhook = "webhook url"

有没有办法遍历所有的 webhook,直到每个服务器都收到消息?

到目前为止我的代码:

@commands.command()
async def eventsend(self, ctx, webhook, *, reason):
  async with aiohttp.ClientSession() as session:
    eventweb = discord.Embed(title = "Incoming  Announcment!", color = 0xfad934, description = reason)
    webhook = Webhook.from_url('url', adapter=AsyncWebhookAdapter(session)) #something here to cycle through url's
    await webhook.send(embed = eventweb ,username='Solamita')

任何帮助将不胜感激!

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    列出所有作为 webhook url 的变量,然后您可以遍历它们

    l = [Server1Webhook, Server2Webhook, Server3Webhook]
    
    @commands.command()
    async def eventsend(self, ctx, webhook, *, reason):
      async with aiohttp.ClientSession() as session:
        eventweb = discord.Embed(title = "Incoming  Announcment!", color = 0xfad934, description = reason)
        for i in l:
            webhook = Webhook.from_url(i, adapter=AsyncWebhookAdapter(session)) #something here to cycle through url's
            await webhook.send(embed = eventweb ,username='Solamita')
    

    【讨论】:

    • 它给了我 2 个错误。要么是参数原因,要么是缺少或缺少 webhook。
    猜你喜欢
    • 1970-01-01
    • 2019-06-02
    • 1970-01-01
    • 2022-01-25
    • 2022-01-07
    • 2020-12-03
    • 2021-06-06
    • 2020-09-23
    • 1970-01-01
    相关资源
    最近更新 更多