如何解决有没有办法停止客户事件? 示例:可能与您更相关的情况:
因此,假设您有一个discord.js消息事件。
if(dropdownlist1.SelectedValue == "Hot Water")
{
drodownlist2.Items.Add(new ListItem("Radiator","Radiator")); //First parameter take datatextfield and second parameter take datavaluefield.
drodownlist2.Items.Add(new ListItem("Heating Controls","Heating Controls"));
}
else
{
drodownlist2.Items.Add(new ListItem("No Power","No Power"));
drodownlist2.Items.Add(new ListItem ("Sockets","Sockets"));
}
是否有任何事情可以让您停止此消息事件。像
bot.on('message',msg => {
//code
})
我很高兴知道。
解决方法
您可以使用return
语句,该语句将终止函数并有选择地返回值。
示例:
function stop() {
console.log('You will see this')
return; // return will completely stop the executing of a function
console.log('But you will not see this')
}
stop()
function addition(num1,num2) {
return num1 + num2 // you can also return values
}
console.log(addition(5,4))
可能与您更相关的情况:
client.on('message',(message) => {
if (message.author.bot) return; // stop execution if author is a bot
message.channel.send("This will only send if the author isn't a bot")
// code...
};
client.on('message',(message) => {
if (message.member.hasPermission('BAN_MEMBERS'))
return message.channel.send("You don't have the required permission.") // returning a value
};
如果我完全误解了您的问题,并且您希望能够在满足条件后停止所有 future 消息触发事件,则可以执行以下操作:
var accepting = true;
client.on('message',(message) => {
if (!accepting) return;
if (message.content === 'stop this') return accepting = false;
// code...
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。