Python 使用Discord.py获取消息内容

Python 使用Discord.py获取消息内容,python,python-3.x,discord.py,discord.py-rewrite,Python,Python 3.x,Discord.py,Discord.py Rewrite,我想要一个像$status idle这样的命令,它将执行以下操作 variblething = 'I am idle' activity = discord.Game(name=variblething) await client.change_presence(status=discord.Status.idle, activity=activity) 然后他们可以执行$message编写您想要的状态 然后它将更改活动消息的内容。我希望这一切都有意义。我当前的代码如下 import disc

我想要一个像
$status idle
这样的命令,它将执行以下操作

variblething = 'I am idle'
activity = discord.Game(name=variblething)
await client.change_presence(status=discord.Status.idle, activity=activity)
然后他们可以执行
$message编写您想要的状态
然后它将更改活动消息的内容。我希望这一切都有意义。我当前的代码如下

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')

首先,我强烈建议您使用前缀和命令decorators/functions

这意味着您的
on_message()
函数不会有一英里长。要设置机器人的命令前缀,可以执行以下操作:

from discord.ext import commands
bot = commands.Bot(command_prefix ='$')
这将允许您执行如下命令:

@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}'))

我从未使用过
@bot.command
,那么该命令是什么?是否是
$status在线活动
?如果这是一个愚蠢的问题,很抱歉。有关命令的文档可在此处找到:。对于我发出的命令,discord中的命令将是
$changeStatus online
。如果您想要活动,您需要更改函数参数。当我执行
$changeStatus idle
时,它没有执行任何操作,控制台中没有任何错误,并且没有更改状态,可能我做错了什么?我不确定,代码对我有用。您需要确保包含前缀并将任何变量(如bot)编辑为您所拥有的任何变量。它似乎会更改活动,但不会更改状态。