![](/img/trans.png)
[英]How can I make my discord bot reply to a message when it contains a specific letter/character?
[英]I want to make my discord bot be able to reply to a command with a username with a link that contains the inputted username
我希望用户输入!fn maxtl ,机器人会通过发布此链接https://fortnitetracker.com/profile/all/maxtl/event来回复
这就是我认为它的样子。 有人可以向我提供有关如何改进此 Discord 机器人 API 使用的任何建议吗?
bot.on("message", (msg) => {
if (msg.content === `!fn ${Username}`) {
msg.reply(`https://fortnitetracker.com/profile/all/${Username}/events`);
}
});
假设您没有对消息进行任何其他处理,这就是您可能需要做的事情。
bot.on("message", (msg) => {
if (!msg.content.startsWith('!')) return;
const arguments = msg.content.split(' ');
const command = arguments.shift();
if (command === '!fn') {
msg.reply(`https://fortnitetracker.com/profile/all/${arguments[0]}/events`);
}
});
这将
我认为这段代码是您正在寻找的东西,我不是 100% 因为我不知道您的机器人的 rest 在做什么。
这段代码将
bot.on('message', async (msg) => {
if (!msg.content.startsWith('!fn')) return;
const commandFound = msg.content.find(mentioned => mentioned === `!fn ${Username}`)
const arguments = commandFound.split(' ');
const userName = arguments.shift();
if (userName) {
try {
await msg.reply(`https://fortnitetracker.com/profile/all/${userName}/events`);
} catch (err) {
console.warn('Failed to respond to mention.');
console.warn(err);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.