使用 Discord.py 获取消息内容
Getting message content with Discord.py
我想要一个像 $status idle
这样的命令,它会执行以下操作
variblething = 'I am idle'
activity = discord.Game(name=variblething)
await client.change_presence(status=discord.Status.idle, activity=activity)
然后他们可以$message write what you want the status to be
然后它将更改 activity 消息的内容。我希望这一切都有意义。我目前的代码如下
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}'))
我想要一个像 $status idle
这样的命令,它会执行以下操作
variblething = 'I am idle'
activity = discord.Game(name=variblething)
await client.change_presence(status=discord.Status.idle, activity=activity)
然后他们可以$message write what you want the status to be
然后它将更改 activity 消息的内容。我希望这一切都有意义。我目前的代码如下
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}'))