有人可以帮我解决错误吗?
Posted
技术标签:
【中文标题】有人可以帮我解决错误吗?【英文标题】: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.";
【问题讨论】:
【参考方案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);
【讨论】:
以上是关于有人可以帮我解决错误吗?的主要内容,如果未能解决你的问题,请参考以下文章
有人可以帮我解决这个错误吗?(Xamarin.Forms)“System.Net.Http.HttpRequestException:'网络子系统已关闭'”