Discord.py使用Webhook向特定协会发送消息

2024-10-01 17:26:17 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我的服务器决定开始这场比赛,为了与其他服务器通信,我们想创建一个命令,我们可以使用他们发送过来的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')

任何帮助都将不胜感激


Tags: 方法代码命令服务器消息urlasyncsession
1条回答
网友
1楼 · 发布于 2024-10-01 17:26:17

列出所有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')

相关问题 更多 >

    热门问题