Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要使用discord bot命令分配变量的帮助吗_Javascript_Discord_Discord.js - Fatal编程技术网

Javascript 需要使用discord bot命令分配变量的帮助吗

Javascript 需要使用discord bot命令分配变量的帮助吗,javascript,discord,discord.js,Javascript,Discord,Discord.js,因此,我正在尝试使用discord.js构建自己的discord机器人。有一件非常重要的事情我想实现。 我想通过bot命令重新分配一个变量。我当前的代码如下所示: client.on("message", (msg) => { if (msg.content.startsWith(config.prefix + "boosting")) { const embed = new Discord.MessageEmbed() .s

因此,我正在尝试使用discord.js构建自己的discord机器人。有一件非常重要的事情我想实现。 我想通过bot命令重新分配一个变量。我当前的代码如下所示:

client.on("message", (msg) => {
  if (msg.content.startsWith(config.prefix + "boosting")) {
    const embed = new Discord.MessageEmbed()
      .setColor("0xd08d11")
      .setTitle("**Random Title**")
      .setDescription(Some description)
      .addFields(
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: "Person 0", value: 'Personvalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Price', value: 'Pricevalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Person 1', value: '40k', inline: true },
        { name: 'Person 2', value: '40k', inline: true },
        { name: 'Person 3', value: '40k', inline: true },
        { name: 'Person 4', value: '40k', inline: true },
      )
      .setThumbnail(logo)
      .setTimestamp()
      .setFooter('created by me or something like that');
    client.channels.cache.get(`here_is_my_channel_id`).send(embed); 
  }
});

client.login(config.token)
let Variable = "Test";

client.on("message", (msg) => {
  if (msg.content.startsWith(config.prefix + "boosting" + " " + Variable)) {
    const embed = new Discord.MessageEmbed()
      .setColor("0xd08d11")
      .setTitle("**Random Title**")
      .setDescription(Variable)
      .addFields(
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: "Person 0", value: 'Personvalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Price', value: 'Pricevalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Person 1', value: '40k', inline: true },
        { name: 'Person 2', value: '40k', inline: true },
        { name: 'Person 3', value: '40k', inline: true },
        { name: 'Person 4', value: '40k', inline: true },
      )
      .setThumbnail(logo)
      .setTimestamp()
      .setFooter('created by me or something like that');
    client.channels.cache.get(`here_is_my_channel_id`).send(embed); 
  }
});

client.login(config.token)
好的,现在我可以输入。boosting从我的机器人获取嵌入消息,但问题是,我想输入。boosting Variable1 Variable2等等,为嵌入消息的属性提供新值。对于属性,我指的是描述、字段名称或值。我试过这样的方法:

client.on("message", (msg) => {
  if (msg.content.startsWith(config.prefix + "boosting")) {
    const embed = new Discord.MessageEmbed()
      .setColor("0xd08d11")
      .setTitle("**Random Title**")
      .setDescription(Some description)
      .addFields(
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: "Person 0", value: 'Personvalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Price', value: 'Pricevalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Person 1', value: '40k', inline: true },
        { name: 'Person 2', value: '40k', inline: true },
        { name: 'Person 3', value: '40k', inline: true },
        { name: 'Person 4', value: '40k', inline: true },
      )
      .setThumbnail(logo)
      .setTimestamp()
      .setFooter('created by me or something like that');
    client.channels.cache.get(`here_is_my_channel_id`).send(embed); 
  }
});

client.login(config.token)
let Variable = "Test";

client.on("message", (msg) => {
  if (msg.content.startsWith(config.prefix + "boosting" + " " + Variable)) {
    const embed = new Discord.MessageEmbed()
      .setColor("0xd08d11")
      .setTitle("**Random Title**")
      .setDescription(Variable)
      .addFields(
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: "Person 0", value: 'Personvalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Price', value: 'Pricevalue', inline: true },
        { name: '\u200B', value: '\u200B' }, //spacer
        { name: 'Person 1', value: '40k', inline: true },
        { name: 'Person 2', value: '40k', inline: true },
        { name: 'Person 3', value: '40k', inline: true },
        { name: 'Person 4', value: '40k', inline: true },
      )
      .setThumbnail(logo)
      .setTimestamp()
      .setFooter('created by me or something like that');
    client.channels.cache.get(`here_is_my_channel_id`).send(embed); 
  }
});

client.login(config.token)
现在我可以写了。boosting测试和这个嵌入消息的描述将具有这个值。
我知道我需要定义变量,但是有没有可能用bot命令重新分配它?例如,它可以从值“Test”更改为“something”。感谢您的帮助

您可以将邮件拆分为一组单词:

const args=message.content.slice(config.prefix.length).split(+/).slice(1)
//示例:`。向全世界的人们问好`
//返回:['hello'、'people'、'of'、'the'、'world']
因此,如果希望获得第一个参数(word),可以使用
args[0]
。对于第二个参数,
args[1]
,依此类推

您已更新代码:

client.on(“消息”(msg)=>{
if(msg.content.startsWith(config.prefix+“boosting”+“”+变量)){
const args=message.content.slice(config.prefix.length).split(+/).slice(1)
const embed=new Discord.MessageEmbed()
.setColor(“0xd08d11”)
.setTitle(“**随机标题**”)
.setDescription(参数[0])
addFields先生(
{name:'\u200B',value:'\u200B'},//间隔符
{name:“Person 0”,value:'Personvalue',inline:true},
{name:'\u200B',value:'\u200B'},//间隔符
{name:'Price',value:'Pricevalue',inline:true},
{name:'\u200B',value:'\u200B'},//间隔符
{name:'Person 1',value:'40k',inline:true},
{name:'Person 2',value:'40k',inline:true},
{name:'Person 3',value:'40k',inline:true},
{name:'Person 4',value:'40k',inline:true},
)
.set缩略图(徽标)
.setTimestamp()文件
.setFooter('由我或类似的人创建');
client.channels.cache.get(`here\u is\u my\u channel\u id`)。send(embed);
}
});
client.login(config.token)

您遇到了哪些错误?谢谢您的回答,帮了我很大的忙。很高兴我能帮忙:)