Webhook带有Bot的切换通道

时间:2020-07-29 22:31:53

标签: discord.py

我希望当您使用命令webhook时,应该在使用代码的通道中发送消息。但是我不知道该怎么做,请帮忙。

   @bot.command()
    async def deneme(ctx, test):
         webhook = Webhook.partial(webhookid, webhooktoken, adapter=RequestsWebhookAdapter())
    
         webhook.send(test, username=ctx.author.name, avatar_url=ctx.author.avatar_url)

1 个答案:

答案 0 :(得分:0)

如果您的频道已创建了一个Webhook,则可以使用ctx.channel.webhooks()选择一个并通过执行WEBHOOK.url()来获取该频道发送的所有Webhook的列表。如果您的频道没有网络挂钩,则可以使用await ctx.channel.create_webhook(name='WEBHOOK NAME')创建一个网络挂钩,您可以将其分配给一个变量,然后使用WEBHOOK.url()获取网址。

注意:仅discord.py-rewrite支持创建Webhook。

或者,您也可以只使用漫游器来回复,而不必使用ctx.channel.send()

来使用Webhook