You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

import requests
import discord
import asyncio
import os
TOKEN = os.environ["TOKEN"]
client = discord.Client()
textchannels = []
members = []
servers = []
destination_channel = "xkcd"
def get_channels_by_name(name):
return [i for i in textchannels if name in]
def get_lastest_num():
resp = requests.get("")
return resp.json()['num']
async def loop():
# latest = get_lastest_num()
latest = 1
while True:
tmp = get_lastest_num()
if latest != tmp:
for channel in get_channels_by_name(destination_channel):
await channel.send("New XKCD:{}".format(tmp))
except discord.errors.Forbidden as e:
print("An error has occured: {}".format(e))
latest = tmp
await asyncio.sleep(30)
async def on_ready():
for server in client.guilds:
for channel in server.channels:
for member in server.members:
print("bot ready")
if __name__ == "__main__":