A discord bot to preview code from github code links directly in discord
Objective is to match this kind of link: github.com/itsvyle/gh-previews/blob/74f1ef26acfec41574d84b335fce0ee431a424af/README.md#L2
This is useful for code review and sharing code snippets in discord, as it makes asking questions about code snippets easier, without the need for screenshots everywhere.
Create a .env
file in the root directory with the following content:
DISCORD_TOKEN=your_discord_bot_token
GITHUB_PAT=<a github PAT to access private repos, this is optional>
Then, run yarn install
and yarn start
to start the bot.
You will of course need yarn, node, and a discord bot created with the token obtained
You can also use the dockerfile to build and run the bot in a container; just mount an --env-file
with the same content as the .env
file, or pass the environment variables directly.
When adding the bot to your server, make sure to give it the following permissions:
- Send Messages
- Read messages/channels
- Read messages history - this is essential as you need to be able to read the message history to reply to a message
- OPTIONAL: manage messages - this will let the bot delete the embed that shows up in the original embed
Discord developper portal screenshot:
This can also be done directly in VSCode:
Once the link is copied, just put it in a discord message, and the bot will answer automatically!
- Add authentication, so that it can access code from private repositories ON REPOS I DONT OWN
- Add support for knowing who edited the file last, etc.
- Add support for not having a line number
- Automatically find files in recent repos when mentioned, and suggest a preview; if the message only contains a mention and is a reply, it uses the content of the previous message