如何让我的 discord.py 重写机器人响应其他机器人而不响应 webhooks?

时间:2021-07-05 19:43:52

标签: discord.py

这不允许机器人响应 webhooks,但它也不允许机器人响应其他机器人

import discord
from discord.ext import commands
from discord import utils

client = discord.Client()


@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
  if message.author.bot:
    return
  else:
    msg = message.content
    webhooks = await message.channel.webhooks()
    webhook = utils.get(webhooks, name = "Backups")
    if webhook is None:
      webhook = await message.channel.create_webhook(name = "Backups")

    await webhook.send(msg, username = message.author.name, avatar_url = message.author.avatar_url)


client.run('TOKEN')

1 个答案:

答案 0 :(得分:0)

您可以检查 Message.webhook_id。如果不是 None,则消息由网络钩子发送

if message.webhook_id is not None:
   return 

...
相关问题