How to use the discord.Client function in discord

To help you get started, we’ve selected a few discord examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CraftSpider / TalosBot / tests / dpytest / runner.py View on Github external
import sys
import asyncio
import logging
import discord
import typing

from . import backend as back


class RunnerConfig(typing.NamedTuple):
    client: discord.Client
    guilds: typing.List[discord.Guild]
    channels: typing.List[discord.abc.GuildChannel]
    members: typing.List[discord.Member]


log = logging.getLogger("discord.ext.tests")
cur_config = None
sent_queue = asyncio.queues.Queue()
error_queue = asyncio.queues.Queue()


async def run_all_events():
    if sys.version_info[1] >= 7:
        pending = filter(lambda x: x._coro.__name__ == "_run_event", asyncio.all_tasks())
    else:
        pending = filter(lambda x: x._coro.__name__ == "_run_event", asyncio.Task.all_tasks())
github DeadBread76 / Raid-Toolbox / RTBFiles / cleanup.py View on Github external
import discord
import sys
import aiohttp
import psutil

token = sys.argv[1]
SERVER = sys.argv[2]
parentprocess = sys.argv[3]
proxy = sys.argv[4]

if not proxy == 'None':
    con = aiohttp.ProxyConnector(proxy="http://"+proxy)
    client = discord.Client(connector=con, status=discord.Status.offline)
else:
    client = discord.Client(status=discord.Status.offline)


@client.event
async def on_ready():
    server = client.get_guild(int(SERVER))
    for channel in server.text_channels:
        myperms = channel.permissions_for(server.get_member(client.user.id))
        if not myperms.send_messages:
            continue
        async for message in channel.history(limit=9999):
            if not psutil.pid_exists(int(parentprocess)):  # Parent is dead, Kill self
                await client.logout()
                sys.exit()
            if message.author == client.user:
                await message.delete()
    await client.close()
github DeadBread76 / Raid-Toolbox / RTBFiles / trafficlight.py View on Github external
import discord
import asyncio
import random
import sys
import aiohttp

useproxies = sys.argv[2]
if useproxies == 'True':
    proxy_list = open("proxies.txt").read().splitlines()
    proxy = random.choice(proxy_list)
    con = aiohttp.ProxyConnector(proxy="http://"+proxy)
    client = discord.Client(connector=con)
else:
    client = discord.Client()
token = sys.argv[1]


@client.event
async def on_ready():
    while not client.is_closed():
        randoms = ['1','2','3']
        presence = (random.choice(randoms))
        if presence == '1':
            await client.change_presence(status=discord.Status.online)
            await asyncio.sleep(3)
        elif presence == '2':
            await client.change_presence(status=discord.Status.idle)
            await asyncio.sleep(3)
github DeadBread76 / Raid-Toolbox / RTBFiles / imagespam.py View on Github external
import asyncio
import random
import sys
import os
import aiohttp

token = sys.argv[1]
tokenno = sys.argv[2]
textchan = sys.argv[3]
useproxies = sys.argv[4]

if useproxies == 'True':
    proxy_list = open("proxies.txt").read().splitlines()
    proxy = random.choice(proxy_list)
    con = aiohttp.ProxyConnector(proxy="http://"+proxy)
    client = discord.Client(connector=con)
else:
    client = discord.Client()

@client.event
async def on_ready():
    counter = 1
    txtchan = client.get_channel(int(textchan))
    while not client.is_closed():
        try:
            if sys.platform.startswith('win32'):
                img = random.choice(os.listdir('.\\spammer\\images'))
                imgdir = '.\\spammer\\images\\'+img
            elif sys.platform.startswith('linux'):
                img = random.choice(os.listdir('spammer/images/'))
                imgdir = 'spammer/images/'+img
            file = discord.File(imgdir)
github lynn / koakuma / koakuma.py View on Github external
if len(items) == NUM_IMAGES:
                            # The URL looks like: /data/sample/__some_tags_here__sample-d5aefcdbc9db6f56ce504915f2128e2a.jpg
                            # We strip the __\w+__ part as it might give away the answer.
                            self.urls = [urllib.parse.urljoin(root, re.sub(r'__\w+__', '', item['large_file_url'])) for item in items]
                            return
                except:
                    print('Connection error. Retrying.')
                time.sleep(0.2)
            print('Ran out of tries, the given tag must not have many images...')
            if manual_tag:
                raise ValueError("Manual tag didn't give enough results!")

game = None
game_master = None
game_channel = None
client = discord.Client()

@client.event
async def on_ready():
    print('Ready; loaded %d tags.' % len(tags))

async def game_say(s):
    await client.send_message(game_channel, s)

@client.event
async def on_message(message):
    global game
    global game_master
    global game_channel
    say = lambda s: client.send_message(message.channel, s)
    if message.author == client.user: return
    if message.channel.name not in GAME_CHANNELS: return
github mitchweaver / Discline / client / client.py View on Github external
import discord
from utils.globals import gc
from utils.settings import settings
import ui.text_manipulation as tm

# inherits from discord.py's Client
class Client(discord.Client):

    # NOTE: These are strings!
    __current_server = ""
    __current_channel = ""
    __prompt = ""

    # discord.Status object
    __status = ""

    # discord.Game object
    __game = ""


    # Note: setting only allows for string types
    def set_prompt(self, string):
        self.__prompt = string.lower()
github amici-ursi / ImagesOfNetwork / images_of / entrypoints / discord-announce.py View on Github external
from images_of import command, settings, Reddit

LOG = logging.getLogger(__name__)

# message type mapping
types = {
    't1':'comment',
    't2':'account',
    't3':'link',
    't4':'message',
    't5':'subreddit',
    't6':'award',
    't8':'promocampaign'
}

CLIENT = discord.Client()
client_id = settings.DISCORD_CLIENTID
token = settings.DISCORD_TOKEN

md_link_pattern = '(\[)([^\]()#\n]+)\]\(([^\]()#\n]+)\)'
md_link_re = re.compile(md_link_pattern, flags=re.IGNORECASE)

@CLIENT.event
@asyncio.coroutine 
def on_ready():
    LOG.info('discord.client: on_ready...')
    LOG.info('discord.client: Logged in as {}'.format(CLIENT.user.name))
    
    inbox_id = '183018837883617280'
    inbox_chan = CLIENT.get_channel(inbox_id)
    falsepos_id = '183605928514420736'
    falsepos_chan = CLIENT.get_channel(falsepos_id)
github appu1232 / Discord-Selfbot / cogs / utils / notify.py View on Github external
import discord
import json

description = '''Subreddit keyword notifier by appu1232'''

bot = discord.Client()
with open('settings/notify.json') as fp:
    notif = json.load(fp)


@bot.event
async def on_message(message):
    if notif['type'] == 'dm' and str(message.author.id) == notif['author'] and str(message.channel.id) == notif['channel']:
        if message.content:
            await message.author.send(message.content)
        else:
            await message.author.send(content=None, embed=message.embeds[0])

bot.run(notif["bot_token"])
github NullPxl / NullCTF / nullctf.py View on Github external
import discord
from discord.ext.commands import Bot
from discord.ext import commands

import help_info
import config_vars

client = discord.Client()
bot = commands.Bot(command_prefix=">")
bot.remove_command('help')

extensions = ['ctf', 'ctftime', 'configuration', 'encoding', 'cipher', 'utility']
cool_names = ['nullpxl', 'Yiggles', 'JohnHammond', 'voidUpdate', 'Michel Ney', 'theKidOfArcrania', 'l14ck3r0x01', 'hasu', 'KFBI', 'mrFu', 'warlock_rootx', 'd347h4ck'] 

@bot.event
async def on_ready():
    print(f"{bot.user.name} - Online")
    print(f"discord.py {discord.__version__}\n")
    print("-------------------------------")

    await bot.change_presence(activity=discord.Game(name=">help | >report \"x\""))

@bot.command()
async def help(ctx, page=None):