Skip to content

Instantly share code, notes, and snippets.

@apacheli
Created August 15, 2021 17:34
Show Gist options
  • Select an option

  • Save apacheli/4aebaa1e454ac33f6d9dda84d97ae56d to your computer and use it in GitHub Desktop.

Select an option

Save apacheli/4aebaa1e454ac33f6d9dda84d97ae56d to your computer and use it in GitHub Desktop.
import aiohttp
import asyncio
import os
class RequestClient:
def __init__(self, token: str):
self.token = token
self.url = "https://api.revolt.chat/"
async def request(self, method: str, route: str, json=None):
headers = {
"Content-Type": "application/json",
"x-bot-token": self.token,
}
url = self.url + route
async with aiohttp.ClientSession(headers=headers) as session:
async with session.request(method, url, json=json) as response:
return await response.json()
def send_message(self, channel: str, **kwargs: dict[str]):
data = {
**kwargs,
"nonce": str(os.urandom(8)),
}
return self.request("POST", f"channels/{channel}/messages", data)
client = RequestClient(os.environ["BOT_TOKEN"])
loop = asyncio.get_event_loop()
loop.run_until_complete(client.send_message("01FD2W5SF0G72CVNH17QCCTQM2", content="# hello world"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment