错误:val 不是非空字符串或有效数字。值=未定义
Posted
技术标签:
【中文标题】错误:val 不是非空字符串或有效数字。值=未定义【英文标题】:error: val is not a non-empty string or a valid number. val=undefined 【发布时间】:2020-12-14 19:37:42 【问题描述】:我正在发出静音命令,但出现此错误
error: val is not a non-empty string or a valid number. val=undefined
我不太清楚为什么会出现这个错误,也不知道如何修复它 这是我的代码:
bot.on('message', async (bot, message, args) =>
if (!message.content.startsWith(PREFIX)) return;
if (message.author.bot) return;
switch (args[0])
case 'mute':
let toMute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if (!toMute) return message.reply('It looks like you didnt specify the user!');
if (toMute.hasPermission('MANAGE_MESSAGES')) return message.reply("can't mute them");
let muterole = message.guild.roles.cache.find(r => r.name === 'muted');
if (!muterole)
try
muterole = await message.guild.roles.create(
name: "muted",
color: "#000000",
permissions: []
)
message.guild.channels.cache.forEach(async (channel, id) =>
await channel.overwritePermission(muterole,
SEND_MESSAGES: false,
ADD_REACTIONS: false
);
);
catch (e)
console.log(e.stack);
return message.channel.send('Cant')
let mutetime = args[1];
if (!mutetime) return message.reply('You didnt specify the time');
await (toMute.addRole(muterole.id));
message.reply(`Successfully muted <@$toMute.id> for $ms(mutetime)`);
setTimeout(function ()
toMute.removeRole(muterole.id);
message.channel.send(`<@$toMute.id> has been unmuted!`);
, ms(mutetime));
);
如果你能帮助我,那就太好了。 另外,我是编码新手,所以如果你能逐步教我,那就太好了 谢谢。
【问题讨论】:
您能否检查一下您是否正确提供了所有方法参数? 【参考方案1】:所以我要回答这个关于我是如何执行定时静音命令的。它与你的有点不同,但仍然做同样的工作。这个命令的一个例子是!mute @test#6969 10m For swearing
const target = message.mentions.members.first();
const tag = message.member.user.tag;
const targettag = target.user.tag;
const author = message.author;
args[2] = args.splice(2, args.length).join(" ");
const modlogEmbed =
color: 0xFF5733,
title: 'MUTE ||',
description: 'Muted Person : ' + targettag + '<@'+ target + '>' + "\n" + 'Reason : ' + args[2] + "\n" + 'Moderator : ' + tag + '<@' + author.id + '>' + "\n" + 'Time : ' + ms(ms(args[1])),
timestamp: new Date(),
footer:
text: 'Lonely Guy is the best',
,
;
const unmuteEmbed =
color: 0xA6D785,
title: 'UNMUTE ||',
description: 'Unmuted Person : ' + targettag + '<@'+ target + '>' + "\n" + 'Moderator : ' + 'Respectrum#7228' + '<@785234591568887829>',
timestamp: new Date(),
footer:
text: 'Lonely Guy is the best',
,
;
const modlog = message.guild.channels.cache.find(channel => channel.id === 'your modlog id');
if(target)
if(message.member.permissions.has('ADMINISTRATOR'))
target.roles.add('the mute role id');
message.reply('U have muted <@' + target + '> for '+ ms(ms(args[1])) + '. Personally, thats an excellent idea.');
modlog.send( embed: modlogEmbed);
setTimeout(function()
target.roles.remove('the mute role id');
modlog.send( embed: unmuteEmbed);
, ms(args[1]));
else
message.reply('you don`t have the facilities for that, big man');
else
message.reply('Ping the member you want to mute.');
如果你想知道每个人都做了什么,就在这里问。
【讨论】:
以上是关于错误:val 不是非空字符串或有效数字。值=未定义的主要内容,如果未能解决你的问题,请参考以下文章
ElasticSearch 将 NULL 值作为空字符串或“N/A”获取