首页 > 解决方案 > 需要不和谐机器人的帮助

问题描述

我想要实现的是当用户输入命令 !finduser 和用户名时,例如“!finduser user3”我希望机器人发布网站网址并将“/user3”添加到末尾,如下所示https:/ /ogusers.com/user3。我知道它令人困惑,但我真的不知道如何解释它。这是当前代码。

if message.content.startswith('!finduser'):
    user = message.content.startswith ('')
    msg = 'https://ogusers.com' + '/' + user
    await client.send_message(message.channel, msg)

标签: pythondiscorddiscord.py

解决方案


您可以使用discord.ext.commands扩展来为您处理大部分命令解析。

from discord.ext import commands

bot = commands.Bot("!")

@bot.command(pass_context=True)
async def finduser(ctx, name):
    await bot.say("https://ogusers.com/{}".format(name))

bot.run("TOKEN")

推荐阅读