A
A
Alexey2021-08-16 10:42:50
C++ / C#
Alexey, 2021-08-16 10:42:50

How to send messages via webhook to a Discord channel?

I have an application written in Visual Studio 2019
And I need to implement sending messages to a specific discord text channel for certain actions while the program is running, how to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Loshara Tupoi, 2021-08-18
@GamerDisclaimer

A ready-made utility with a solution, code below, and a tutorial
Link to the utility
I've been digging around with the solution for quite some time, rummaged through the floor of Google, spent several hours
And finally I did it!
The author of the question, please mark the answer for the efforts :)
By the way, quite an interesting topic! I will not demolish the developments
And the first thing I want to say is that the program is written in Python , so we need an installed python, and the discord.py

library Here is a brief tutorial for you:

Step by step webhook creation

611cdea27551f113640884.jpeg
611cdeda67dbe369516144.jpeg
611cdf354562a461795201.jpeg

Create a file with the extension .py
Enter the following code:
from discord import Webhook, AsyncWebhookAdapter
import asyncio
import aiohttp


async def send () :
    URL = input('Введите URL вашего вебхука: ')
    Message = input('Введите ваше сообщение: ')

    async with aiohttp.ClientSession() as session:
        webhook = Webhook.from_url(URL, adapter=AsyncWebhookAdapter(session))
        await webhook.send(Message)


asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(send())

We save, we start, we enter URL and our message
We check. Everything is working
611cebaa75960288108519.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question