簡體   English   中英

Discord.py 使用 webhooks 向特定公會發送消息

[英]Discord.py Sending a message to specific guilds using webhooks

所以我的服務器決定開始這場比賽,為了與其他所有服務器進行通信,我們想要創建一個命令,我們可以在其中使用他們發送的 webhook 並使用它來傳達信息。 例子:

Server1Webhook = "webhook url"

Server2Webhook = "webhook url"

Server3Webhook = "webhook url"

有沒有辦法遍歷所有的 webhooks 直到每個服務器都收到消息?

到目前為止我的代碼:

@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')

任何幫助將不勝感激!

列出作為 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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM