EchoTheAlpha
EchoTheAlpha

Reputation: 422

Getting message content with Discord.py

I would like to have a command like $status idle and it would do the follow

variblething = 'I am idle'
activity = discord.Game(name=variblething)
await client.change_presence(status=discord.Status.idle, activity=activity)

then they can do $message write what you want the status to be then it would change what the activity message is. I hope this all makes sense. My current code is the following

import discord
client = discord.Client()

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

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('$helloThere'):
        await message.channel.send('General Kenobi')

Upvotes: 0

Views: 2086

Answers (1)

Kelo
Kelo

Reputation: 1893

Firstly I would highly advise that you use prefixes and the command decorators/functions.

This means that your on_message() function won't be a mile long. To set your bot's command prefix, you can do:

from discord.ext import commands
bot = commands.Bot(command_prefix ='$')

This will allow you to make commands like so:

@bot.command()
async def changeStatus(ctx, *, status):

    if status == 'online':
        new_status = discord.Status.online
    elif status == 'offline':
        new_status = discord.Status.offline
    elif status == 'idle':
        new_status = discord.Status.idle
    elif status == 'dnd':
        new_status = discord.Status.dnd
    else:
        return

    await bot.change_presence(status=new_status, activity=discord.Game(f'I am {status}'))

Upvotes: 1

Related Questions