简体   繁体   English

我如何才能使它只发送消息的一部分? 不和谐.js

[英]How do i make so it only sends a part of the message? discord.js

I got a problem here where i cant find out how i make so it will remove the !suggest in the message thats gonna be sent im trying to make it so when someone uses !suggest {suggestion} in the specific channel a message will be sent in the #suggestions channel ive got the specific channel up i just want to remove so instead of the bot saying "@user#1234 have suggested !suggest add a goodbye command" it will only say "@user#1234 have suggested: add a goodbye command" basically just removing !suggest heres the code its JavaScript我在这里遇到了一个问题,我无法找到我是如何制作的,因此它将删除将要发送的消息中的 !suggest 我正在尝试制作它,因此当有人在特定频道中使用 !suggest {suggest} 时,将发送一条消息在#suggestions 频道中,我打开了特定频道,我只想删除它,而不是机器人说“@user#1234 建议添加再见命令”,它只会说“@user#1234 建议:添加一个再见命令”基本上只是删除!建议这里是它的 JavaScript 代码

//Suggestions
client.on("message", message => {
if (message.content.startsWith("!suggest")){
return client.channels.get('514917785248202773').send(message.author.tag+" 
suggested " + message.content)
}
});

how would i make it so it removes the !suggest part only?我将如何使它只删除 !suggest 部分? cant find anything on here or internet at all在这里或互联网上根本找不到任何东西

A possibility is to split the message on every space (' '), removing the first element (which is always the command), and recombining the string array.一种可能性是在每个空格 (' ') 上拆分消息,删除第一个元素(始终是命令),然后重新组合字符串数组。

Example:例子:

 let message = "!suggest add a goodbye command" const args = message.trim().split(' '); args.shift(); console.log(args.join(' '));

client.on('message', msg => {
if(msg.content.startsWith('!suggest')) {
let message = msg.content.split(" ");
const suggestion = message[1];
client.channels.get('514917785248202773').send(message.author.tag+" 
suggested " + suggestion)
}
}

this makes 'message' an array这使“消息”成为一个数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 discord 机器人在 discord.js 中发送消息后有表情符号反应? - How do I make discord bot have an emoji reaction after it sends its message in discord.js? 如何使用户不能连续发布多条消息,discord.js - How do I make it so that a user can not post more than one message in a row, discord.js Discord.js | 我如何制作通过 id 发送到特定频道的命令 - Discord.js | How do i make a command that sends to a specific channel by id Discord.js | 如何制作在用户加入时发送用户信息的代码? - Discord.js | How do I make a code that sends the users info when they join? 如何使其仅在其准确时才响应(Discord.JS) - How to make it so it only respond if its exact (Discord.JS) Discord.js | 我如何做到这一点,使其每 2 或 3 个单词输入一个新行? - Discord.js | How do I make that so it enters a new line every 2 or 3 words? 当有人在 Discord.js 中键入未知命令时,如何发出“无效命令”消息? - How do I make an "Invalid Command" message when someone types an unknown command in Discord.js? 我如何让我的代码在删除消息之前等待(discord.js) - how do i make my code wait before deleting a message (discord.js) 如何让它在 discord.js 的嵌入式消息中显示图片? - How do I make it show a picture in an embedded message on discord.js? 如何让 DIscord.js 机器人实际回复消息? - How do I make a DIscord.js bot actually reply to a message?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM