Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2016 13:15
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Karunamon/d347f8f952323133f6c6679f02c46a86 to your computer and use it in GitHub Desktop.
Bible verse cog for Red-Discordbot
import discord
import requests
import json
import urllib
from discord.ext import commands
class Bible:
def __init__(self, bot): = bot
self.URL = ""
async def api_request(self, arg, mode='json', formatting='plain'):
geturl = "{U}/api?passage={a}&formatting={f}&type={m}".format(
r = requests.get(geturl)
if r.status_code is not 200:
await"Error accessing {U}, error {E}. Please notify a minister.".format(
return r
async def bible(self, ref1, ref2, ref3=None):
Access a bible verse by it's direct reference
reference: Scripture reference (E.g '1 Cor 2:2, John 3:16-17')
# Work around bot quoting rules, we don't want users to need to
# enclose scripture references in quotes.
# Example: 1 John 5:19
# John 3:16
if ref3:
ref = " ".join((ref1,ref2,ref3))
ref = " ".join((ref1,ref2))
verseref = urllib.parse.quote_plus(ref)
r = await self.api_request(verseref)
js_response = json.loads(r.text)
for passage in js_response:
def setup(bot):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment