【问题标题】:Can someone help me with an err?有人可以帮我解决错误吗?
【发布时间】:2021-07-10 04:49:34
【问题描述】:

所以我为我的不和谐机器人做了一个秒表命令,但它说:TypeError: Cannot read property 'id' of undefined on message.guild.id) 请帮助我找出为什么会发生一周

const Discord = require('discord.js');
const StopWatch = require("timer-stopwatch-dev"); 
const moment = require('moment');

module.exports = {
    name: 'duty',
    description: "This is a stopwatch command",
    async execute(client, message, args, CurrentTimers) {
      try {
          let guildTimers = CurrentTimers.get(message.guild.id);
          let guildTimersUser = guildTimers.get(message.author.id);
          if(!guildTimersUser){ guildTimers.set(message.author.id, new StopWatch()); guildTimersUser = guildTimers.get(message.author.id); };

 if(!args[0] || args[0] === 'on'){
   if(guildTimersUser.isRunning()) return message.channel.send('You need to stop your shift first!')
   guildTimersUser.start();
   message.channel.send('You have started your shift')
 } else if(args[0] === 'off'){
  if(!guildTimersUser.isRunning()) return message.channel.send('You need to start the Stopwatch first!')
  guildTimersUser.stop();
  message.channel.send(new Discord.RichEmbed().setTitle('You have stopped the Stopwatch!').setDescription('Total Time: ' + dhm(guildTimersUser.ms)).setTimestamp());
 }

 }
 
 catch(err) {
   console.log(err)
 }

 function dhm(ms){
  days = Math.floor(ms / (24*60*60*1000));
  daysms=ms % (24*60*60*1000);
  hours = Math.floor((daysms)/(60*60*1000));
  hoursms=ms % (60*60*1000);
  minutes = Math.floor((hoursms)/(60*1000));
  minutesms=ms % (60*1000);
  sec = Math.floor((minutesms)/(1000));
  return days+" days, "+hours+" hours, "+minutes+" minutes, "+sec+" seconds.";
    }
   }
  }

【问题讨论】:

    标签: javascript discord discord.js stopwatch


    【解决方案1】:

    Discord Embeds可以被创建并发送到频道。

    来自文档:

    // at the top of your file
    const Discord = require('discord.js');
    
    // inside a command, event listener, etc.
    const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#0099ff')
        .setTitle('Some title')
        .setURL('https://discord.js.org/')
        .setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
        .setDescription('Some description here')
        .setThumbnail('https://i.imgur.com/wSTFkRM.png')
        .addFields(
            { name: 'Regular field title', value: 'Some value here' },
            { name: '\u200B', value: '\u200B' },
            { name: 'Inline field title', value: 'Some value here', inline: true },
            { name: 'Inline field title', value: 'Some value here', inline: true },
        )
        .addField('Inline field title', 'Some value here', true)
        .setImage('https://i.imgur.com/wSTFkRM.png')
        .setTimestamp()
        .setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
    
    channel.send(exampleEmbed);
    

    【讨论】:

      猜你喜欢
      • 2016-07-09
      • 1970-01-01
      • 2019-09-23
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 2022-10-23
      • 2021-05-30
      相关资源
      最近更新 更多