Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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
discord.js-等待消息并检查dm消息_Discord.js - Fatal编程技术网

discord.js-等待消息并检查dm消息

discord.js-等待消息并检查dm消息,discord.js,Discord.js,我所做的一切都是在工作,我一直在互联网上寻找,没有什么能帮助我 请帮忙,我的代码在下面。 我在node.js 14.15.0中使用discord.js, 这段代码不在main.js文件中,所以客户端。行不通, 我正在使用命令的集合 我试图检查用户何时响应其dm中的消息 if(message.channel.type === 'dm'){ message.channel.awaitMessages(message.author.id, {max: 1, time: 30000}).then

我所做的一切都是在工作,我一直在互联网上寻找,没有什么能帮助我 请帮忙,我的代码在下面。 我在node.js 14.15.0中使用discord.js, 这段代码不在main.js文件中,所以客户端。行不通, 我正在使用命令的集合

我试图检查用户何时响应其dm中的消息

if(message.channel.type === 'dm'){
    message.channel.awaitMessages(message.author.id, {max: 1, time: 30000}).then(collected => {
         console.log(message.author);
         if(collected.first().content.toLowerCase() == 'cancel'){
              message.author.send('canceled');
         }
    }).catch(err =>{
         message.author.send('took too long canceling');
    });
 };

在DM频道等待消息时,
message.author.send
无效。
由于这些DMs仍在通道
message.channel.send
中,因此可以正常工作。
示例代码:

client.on('message',message=>{//添加事件侦听器
if(message.channel.type==='dm'){//如果消息是通过直接消息发送的
message.channel.awaitMessages(message.author.id,{max:1,time:30000})。然后(collected=>{//等待下一条消息)
if(collected.first().content.toLowerCase()=='cancel'){//如果等待的消息等于'cancel'
message.channel.send('cancelled prompt');//让用户知道他们的电子请求已被取消
}
}).接住{
message.channel.send('Timeout procedued,canceling');//如果用户已用完时间,请通知他们
};
}
});

“不起作用”不足以诊断问题。怎么了?您是否收到任何错误?我无法使用client.on,因为我是在main.js中使用的,我调用命令的方式是通过另一个文件夹中的集合使用module.exports。我要做的是让这个脚本运行在不和谐中,当一个玩家说这个命令时,它会在服务器外部向他们发送一个带有嵌入的dm,然后我试图等待他们在该dm中响应,但它不起作用。关于这个更好的解释,您需要在代码的某个地方传递客户机对象。我的建议是,当你导出文件时,把所有的文件都传递给客户。我不知道你的意思。我的client.on:wont格式正确:client.on('message',message=>{if(!message.content.startsWith(prefix)| | | message.author.bot)return;const args=message.content.slice(prefix.length).split(+/);const command=args.shift().toLowerCase();if(command=='embed'){client.commands.get('embed')。执行(message,args)}else if(command=='info'){client.commands.get('info').execute(message,args);}else if(command=='xera'){client.commands.get('xera').execute(message,args);};您将
.execute(message,args)
更改为
.execute(message,args,client)
。当我输入一个数字时,这个错误显示了对此的想法吗?未处理的PromisejectionWarning:TypeError:Function.prototype.apply在[my user id]上被调用,该id是字符串而不是函数