Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

discord.py task loop

import discord
from discord.ext import tasks

client = discord.Client()

@tasks.loop(seconds = 10) # repeat after every 10 seconds
async def myLoop():
    # your work


myLoop.start()
client.run("token")
Comment

task.loop discord.py

import discord
from discord.ext import commands, tasks
from twitch import TwitchClient
from pprint import pformat


client = TwitchClient(client_id='<twitch token>')

bot = commands.Bot(command_prefix='$')

@bot.event
async def on_ready():
    print('We have logged in as {0.user}'.format(bot))

@bot.command()
async def info(ctx, username):
    response = await ctx.send("Querying twitch database...")
    try:
        users = client.users.translate_usernames_to_ids(username)
        for user in users:
            print(user.id)
            userid = user.id
        twitchinfo = client.users.get_by_id(userid)
        status = client.streams.get_stream_by_user(userid)
        if status == None:
            print("Not live")
            livestat = twitchinfo.display_name + "is not live"
        else:
            livestat = twitchinfo.display_name + " is " + status.stream_type
        responsemsg = pformat(twitchinfo) + "
" + livestat
        await response.edit(content=responsemsg)
    except:
        await response.edit(content="Invalid username")

bot.run("<discord token>")
Comment

PREVIOUS NEXT
Code Example
Python :: image data generator keras with tf.data.Data.from_generator 
Python :: pandas convert string to float 
Python :: python create unreadable save file 
Python :: return array of sorted objects 
Python :: how to split from a specific charecter to the end of the string in python 
Python :: Split a list based on a condition 
Python :: python dataframe sort by column name 
Python :: parse invoice python 
Python :: allow x_frame_options django 
Python :: python variables 
Python :: s.cookie.set python 
Python :: Time series missing values 
Python :: how to start coding in python 
Python :: concatenacion python 
Python :: how to run python in the browser 
Python :: sorted function in python 3 
Python :: time zone in python 
Python :: database with python connection 
Python :: python class example 
Python :: examples of function in python 
Python :: hide text in plot 
Python :: how to create fastapi 
Python :: how to check if all values in list are equal python 
Python :: python align output 
Python :: get index of first true value numpy 
Python :: python string first letter uppercase and second letter in lowercase 
Python :: pd df set index 
Python :: python test coverage 
Python :: for loop python 
Python :: recurrent neural network pytorch 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =