Отправка сообщений бот в дискорде

Shishkin

Известный
Автор темы
488
249
Если я правильно понимаю, то система ботов в дискорде, построена примерна так-же как и в vk
То есть если мы переходим по определенной ссылки - отправляется сообщение от бота (или группы, если мы говорим про вк)
Вот и вопрос заключается в том, что я не могу понять по какой именно ссылки надо переходить, и как её составлять
С документацией к созданию ботов в дс - туплю.
 
Последнее редактирование:
Решение
/ds.msg [text]
Lua:
local effil = require 'effil'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local url = 'юрл вебхука'
local data = {
    ['content'] = 'text',
    ['username'] = 'Sended from .lua script!'
}

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('ds.msg', function(arg)
        data['content'] = u8(arg)
        asyncHttpRequest('POST', url, {headers = {['content-type'] = 'application/json'}, data = encodeJson(data)},
        function(response)
            sampAddChatMessage('[WebHook] [OK] SENDED', -1)
            for k, v in pairs(response) do
                print(k, v)
            end
        end,
        function(err)
           sampAddChatMessage('[WebHook]...

bottom_text

Известный
675
318
я не прошу показать как его сделать через пайтен, я прошу дать мне ссылку с помощью которой отправляются сообщения (если оно всё так работает)
Почитай про дискорд webhook'и, там надо пост запрос на url( ссылку) вебхука делать с нужными данными и от имени бота-вебхука будет отправлено сообщение. Наверно это то, что тебе нужно
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,777
11,221
/ds.msg [text]
Lua:
local effil = require 'effil'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local url = 'юрл вебхука'
local data = {
    ['content'] = 'text',
    ['username'] = 'Sended from .lua script!'
}

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('ds.msg', function(arg)
        data['content'] = u8(arg)
        asyncHttpRequest('POST', url, {headers = {['content-type'] = 'application/json'}, data = encodeJson(data)},
        function(response)
            sampAddChatMessage('[WebHook] [OK] SENDED', -1)
            for k, v in pairs(response) do
                print(k, v)
            end
        end,
        function(err)
           sampAddChatMessage('[WebHook] [ERROR] error: '..err, -1)
        end)
    end)
    wait(-1)
end

function asyncHttpRequest(method, url, args, resolve, reject)
   local request_thread = effil.thread(function (method, url, args)
      local requests = require 'requests'
      local result, response = pcall(requests.request, method, url, args)
      if result then
         response.json, response.xml = nil, nil
         return true, response
      else
         return false, response
      end
   end)(method, url, args)
   -- Если запрос без функций обработки ответа и ошибок.
   if not resolve then resolve = function() end end
   if not reject then reject = function() end end
   -- Проверка выполнения потока
   lua_thread.create(function()
      local runner = request_thread
      while true do
         local status, err = runner:status()
         if not err then
            if status == 'completed' then
               local result, response = runner:get()
               if result then
                  resolve(response)
               else
                  reject(response)
               end
               return
            elseif status == 'canceled' then
               return reject(status)
            end
         else
            return reject(err)
         end
         wait(0)
      end
   end)
end
1644948205927.png
 
Последнее редактирование:
  • Нравится
Реакции: P!NK. и Shishkin