python - 需要不和谐机器人的帮助
问题描述
我想要实现的是当用户输入命令 !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)
解决方案
您可以使用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")
推荐阅读
- android - Espresso 无法启动其他活动
- c++ - 从线程执行成员方法时出现分段错误
- angular - 检测 @ViewChild() 中的值何时发生变化
- javascript - 在 Vue 的组件脚本中使用 slot-scoped 数据
- automated-tests - VSTS 发布管道运行后如何测试?
- neural-network - RNN 反向传播时间
- angular - Angular 2 Primeng 消息服务未显示消息
- java - PHP if-else 主体都在执行
- android - SQL 查询没有创建我的列?
- android - 使用 Glide V4 的相同 URL、不同图像的最佳性能