Ejemplo n.º 1
0
        with open('characters.json') as f:
            data = json.load(f)
            characters = {
                k: cattr.structure(v, Character)
                for k, v in data.items()
            }
            await client.message_create(msg.channel,
                                        "Successfully loaded the characters")


@Faito.commands
async def stats(client: Client, msg: Message):
    """
    Send the user's statistics
    :param client:
    :param msg:
    :return:
    """
    user = msg.author
    print(user.id)
    # todo get the actual stats
    stats = characters[msg.author.id]
    embed = Embed(title=f'Stats for {user.name}',
                  description="\n".join(
                      [f'{k.upper()}: {v}' for k, v in stats.items()]))
    await client.message_create(msg.channel, embed=embed)


if __name__ == '__main__':
    Faito.start()
Ejemplo n.º 2
0
# Replace this with your bot token, see topics/getting_started.md to see how you can get one
TOKEN = ''

# Create your client instance by using your bot token
Sakuya = Client(TOKEN)


# Register event handler for message create event. When a message is received the decorated function will be called.
#
# Events are dispatched asynchronously so multiple events can be handled in parallel.
@Sakuya.events
async def message_create(client, message):
    if message.content == '!ping':
        # Sending message can fail due to network error or by lack of permissions.
        #
        # If exception is not explicitly caught it will be logged to stderr and ignored.
        await client.message_create(message.channel, 'pong')


# Register handler for the `ready` event. Ready is called when the client shards are all booted up.
@Sakuya.events
async def ready(client):
    # Hata has various format codes for Discord entities
    #
    # In this case `f` stands for `.full_name` property.
    print(f'{client:f} is connected!')


Sakuya.start()
Ejemplo n.º 3
0

@Pichu.interactions(guild=GUILD)
async def textcat(client, event):
    """I will send textcats :3"""
    try:
        async with HTTP.get(BASE_URL+'/cat') as response:
            if response.status != 200:
                return "Couldn't contact the API right now... OwO"
            data = await response.json()
        return data['cat']
    except (OSError, ConnectionError):
        return None


@Pichu.interactions(guild=GUILD)
async def why(client, event):
    """why are you using this commands?"""
    try:
        async with HTTP.get(BASE_URL+'/why') as response:
            if response.status != 200:
                return "Couldn't contact the API right now... WHY?"
            data = await response.json()
        return data['why']
    except (OSError, ConnectionError):
        return None


# starting the bot
Pichu.start()